throw new UnauthorizedException("Not allowed to change " . implode(' or ', array_keys($forbidden)));
}
}
- if (isset($record['plaintext_password'])) {
+ if (isset($record['password'])) {
if (!empty($record['hashed_password'])) {
- throw new API_Exception("Ambiguous password parameters: Cannot pass plaintext_password AND hashed_password.");
+ throw new API_Exception("Ambiguous password parameters: Cannot pass password AND hashed_password.");
}
- if (empty($record['plaintext_password'])) {
+ if (empty($record['password'])) {
throw new API_Exception("Disallowing empty password.");
}
}
/**
* This is called with the values for a record fully loaded.
*
- * Note that we will now have hashed_password, as well as possibly plaintext_password.
+ * Note that we will now have hashed_password, as well as possibly password.
*
*/
protected function validateValues() {
}
// If changing a password, require user to re-authenticate as themself.
- if (isset(($values['plaintext_password'])) && !$hasAuthenticated) {
+ if (isset(($values['password'])) && !$hasAuthenticated) {
throw new UnauthorizedException("Unauthorized");
}
}
*/
protected function write(array $items) {
foreach ($items as &$item) {
- // If given, convert plaintext_password to hashed_password now.
- if (isset($item['plaintext_password'])) {
- $item['hashed_password'] = Security::singleton()->hashPassword($item['plaintext_password']);
- unset($item['plaintext_password']);
+ // If given, convert password to hashed_password now.
+ if (isset($item['password'])) {
+ $item['hashed_password'] = Security::singleton()->hashPassword($item['password']);
+ unset($item['password']);
}
}
return parent::write($items);
$userID = User::create(FALSE)
->setValues([
'username' => 'testuser1',
- 'plaintext_password' => 'shhh',
+ 'password' => 'shhh',
'contact_id' => $stafferContactID,
'roles:name' => ['staff'],
'email' => 'testuser1@example.org',
$userId = \CRM_Core_BAO_UFMatch::getUFId($stafferContactID);
$this->assertNotNull($userId);
- $this->assertArrayNotHasKey('plaintext_password', $user);
+ $this->assertArrayNotHasKey('password', $user);
$this->assertMatchesRegularExpression('/^[$].+[$].+/', $user['hashed_password']);
// Update to the loaded values should NOT result in the password being changed.
// Now move on to tests with checkPermissions:TRUE
// Check we are allowed to update this user's password if we provide our own, since we have 'cms:administer users'
- // ...by plaintext_password
+ // ...by password
$previousHash = $updatedUser['hashed_password'];
$updatedUser = User::update(TRUE)
- ->addValue('plaintext_password', 'topSecret')
+ ->addValue('password', 'topSecret')
->addWhere('id', '=', $user['id'])
->setActorPassword('secret1')
->setReload(TRUE)
// Check that if we don't supply OUR correct password, we're not allowed to update the user's password.
try {
User::update(TRUE)
- ->addValue('plaintext_password', 'anotherNewPassword')
+ ->addValue('password', 'anotherNewPassword')
->addWhere('id', '=', $user['id'])
->setActorPassword('wrong pass')
->execute();
// Check that if we don't supply OUR password at all, we're not allowed to update the user's password.
try {
User::update(TRUE)
- ->addValue('plaintext_password', 'anotherNewPassword')
+ ->addValue('password', 'anotherNewPassword')
->addWhere('id', '=', $user['id'])
->execute();
$this->fail("Expected UnauthorizedException got none.");
// Check we are allowed to update our own password if we provide the current one.
$updatedUser = User::update(TRUE)
->setActorPassword('topSecret')
- ->addValue('plaintext_password', 'ourNewSecret')
+ ->addValue('password', 'ourNewSecret')
->addWhere('id', '=', $user['id'])
->setReload(TRUE)
->execute()->first();
// Check that if we don't supply OUR correct password, we're not allowed to update our password.
try {
User::update(TRUE)
- ->addValue('plaintext_password', 'anotherNewPassword')
+ ->addValue('password', 'anotherNewPassword')
->addWhere('id', '=', $user['id'])
->setActorPassword('wrong pass')
->execute();
// Check that if we don't supply OUR password at all, we're not allowed to update the user's password.
try {
User::update(TRUE)
- ->addValue('plaintext_password', 'anotherNewPassword')
+ ->addValue('password', 'anotherNewPassword')
->addWhere('id', '=', $user['id'])
->execute();
$this->fail("Expected UnauthorizedException got none.");
// Check that we're not allowed to update the admin user's password, since we are not an admin.
try {
User::update(TRUE)
- ->addValue('plaintext_password', 'anotherNewPassword')
+ ->addValue('password', 'anotherNewPassword')
->addWhere('id', '=', $adminUserID)
->setActorPassword('ourNewSecret')
->execute();