Example #1
0
/**
 * Encrypt a username/password.
 *
 * @param string $userid ID of the user
 * @param string $password Password of the user
 * @return string Hashed password
 * @deprecated Use User::crypt() or User::oldCrypt() instead
 */
function wfEncryptPassword($userid, $password)
{
    wfDeprecated(__FUNCTION__);
    # Just wrap around User::oldCrypt()
    return User::oldCrypt($password, $userid);
}
 /**
  * Add a user to the external authentication database.
  * Return true if successful.
  *
  * @param User $user
  * @param string $password
  * @return bool
  * @access public
  */
 function addUser($user, $password)
 {
     $fname = 'GlobalAuth::addUser';
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select($this->tablename, array('user_id', 'user_wiki', 'user_password'), array('user_name' => $user->getName()), 'GlobalAuth::addUser');
     $create = true;
     $first = true;
     foreach ($res as $row) {
         if ($first) {
             # Set create to false for now. We've found entries for
             # this username. Now we have to check whether we allow
             # the creation of parallel accounts
             $first = $create = false;
         }
         # There is already an account. Don't create a new account
         if ($row->user_wiki == '*' || $row->user_wiki == $this->thiswiki) {
             return false;
         }
         # The password matches one of the already existing accounts.
         # Allow creation of an account.
         if ($row->user_password == User::oldCrypt($password, $row->user_id)) {
             $create = true;
         }
     }
     if (!$create) {
         return false;
     }
     # We don't conflict with an already existing account. Now set up the new account.
     # If $first is still true, there's no user in any wiki yet with this name. We can
     # create a global account ('*') for it. Otherwise, we just create an account for
     # $this->thiswiki.
     $seqVal = $dbw->nextSequenceValue('user_user_id_seq');
     $wiki = $first ? '*' : $this->thiswiki;
     $dbw->insert($this->tablename, array('user_id' => $seqVal, 'user_name' => $user->getName(), 'user_password' => '', 'user_email' => $user->getEmail(), 'user_email_authenticated' => $dbw->timestampOrNull($user->getEmailAuthenticationTimestamp()), 'user_real_name' => $user->getRealName(), 'user_token' => $user->mToken, 'user_wiki' => $wiki), $fname);
     # Query back to get the user_id
     $row = $dbw->selectRow($this->tablename, array('user_wiki', 'user_name', 'user_password', 'user_email', 'user_email_authenticated', 'user_real_name', 'user_token'), array('user_name' => $user->getName(), 'user_wiki' => $wiki), $fname);
     $this->data = $row;
     # Now that we know the ID, we can change the password
     $this->setPassword($password);
     return true;
 }