setPassword() public method

Set the necessary attribute to store a hash of the user's password.
Since: 1.10.0
public setPassword ( string $password ) : void
$password string The password to be hashed
return void
 /**
  * Called before each test object.
  */
 public function __construct()
 {
     parent::__construct();
     $this->user = new \ElggUser();
     $this->user->username = '******' . rand();
     $this->user->email = '*****@*****.**' . rand();
     $this->user->name = 'fake user ' . rand();
     $this->user->access_id = ACCESS_PUBLIC;
     $this->user->setPassword(rand());
     $this->user->owner_guid = 0;
     $this->user->container_guid = 0;
     $this->user->save();
 }
 public function testUpdateACL()
 {
     // another fake user to test with
     $user = new \ElggUser();
     $user->username = '******' . rand();
     $user->email = '*****@*****.**' . rand();
     $user->name = 'fake user';
     $user->access_id = ACCESS_PUBLIC;
     $user->setPassword(rand());
     $user->owner_guid = 0;
     $user->container_guid = 0;
     $user->save();
     $acl_id = create_access_collection('test acl');
     $member_lists = array(array($this->user->guid, $user->guid), array($user->guid), array($this->user->guid), array());
     foreach ($member_lists as $members) {
         $result = update_access_collection($acl_id, $members);
         $this->assertTrue($result);
         if ($result) {
             $q = "SELECT * FROM {$this->dbPrefix}access_collection_membership\n\t\t\t\t\tWHERE access_collection_id = {$acl_id}";
             $data = get_data($q);
             if (count($members) == 0) {
                 $this->assertFalse($data);
             } else {
                 $this->assertEqual(count($members), count($data));
             }
             foreach ($data as $row) {
                 $this->assertTrue(in_array($row->user_guid, $members));
             }
         }
     }
     delete_access_collection($acl_id);
     $user->delete();
 }
Esempio n. 3
0
/**
 * Create a new user from Twitter information
 * 
 * @param object $twitter Twitter OAuth response
 * @return ElggUser
 */
function twitter_api_create_user($twitter)
{
    // check new registration allowed
    if (!twitter_api_allow_new_users_with_twitter()) {
        register_error(elgg_echo('registerdisabled'));
        forward();
    }
    // Elgg-ify Twitter credentials
    $username = $twitter->screen_name;
    while (get_user_by_username($username)) {
        // @todo I guess we just hope this is good enough
        $username = $twitter->screen_name . '_' . rand(1000, 9999);
    }
    $password = generate_random_cleartext_password();
    $name = $twitter->name;
    $user = new ElggUser();
    $user->username = $username;
    $user->name = $name;
    $user->access_id = ACCESS_PUBLIC;
    $user->setPassword($password);
    $user->owner_guid = 0;
    $user->container_guid = 0;
    if (!$user->save()) {
        register_error(elgg_echo('registerbad'));
        forward();
    }
    return $user;
}
Esempio n. 4
0
 /**
  * Registers a user, returning false if the username already exists
  *
  * @param string $username              The username of the new user
  * @param string $password              The password
  * @param string $name                  The user's display name
  * @param string $email                 The user's email address
  * @param bool   $allow_multiple_emails Allow the same email address to be
  *                                      registered multiple times?
  *
  * @return int|false The new user's GUID; false on failure
  * @throws \RegistrationException
  */
 function register($username, $password, $name, $email, $allow_multiple_emails = false)
 {
     // no need to trim password.
     $username = trim($username);
     $name = trim(strip_tags($name));
     $email = trim($email);
     // A little sanity checking
     if (empty($username) || empty($password) || empty($name) || empty($email)) {
         return false;
     }
     // Make sure a user with conflicting details hasn't registered and been disabled
     $access_status = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     if (!validate_email_address($email)) {
         throw new \RegistrationException(_elgg_services()->translator->translate('registration:emailnotvalid'));
     }
     if (!validate_password($password)) {
         throw new \RegistrationException(_elgg_services()->translator->translate('registration:passwordnotvalid'));
     }
     if (!validate_username($username)) {
         throw new \RegistrationException(_elgg_services()->translator->translate('registration:usernamenotvalid'));
     }
     if ($user = get_user_by_username($username)) {
         throw new \RegistrationException(_elgg_services()->translator->translate('registration:userexists'));
     }
     if (!$allow_multiple_emails && get_user_by_email($email)) {
         throw new \RegistrationException(_elgg_services()->translator->translate('registration:dupeemail'));
     }
     access_show_hidden_entities($access_status);
     // Create user
     $user = new \ElggUser();
     $user->username = $username;
     $user->email = $email;
     $user->name = $name;
     $user->access_id = ACCESS_PUBLIC;
     $user->setPassword($password);
     $user->owner_guid = 0;
     // Users aren't owned by anyone, even if they are admin created.
     $user->container_guid = 0;
     // Users aren't contained by anyone, even if they are admin created.
     $user->language = _elgg_services()->translator->getCurrentLanguage();
     if ($user->save() === false) {
         return false;
     }
     // Turn on email notifications by default
     set_user_notification_setting($user->getGUID(), 'email', true);
     return $user->getGUID();
 }