genRandomPassword() public static method

Generates a random, hopefully pronounceable, password. This can be used when resetting automatically a user's password.
public static genRandomPassword ( ) : string
return string A random password
示例#1
0
 /**
  * Resets a user's password. Used for example when the user does not
  * remember the existing password.
  *
  * @param string $userId  The user id for which to reset the password.
  *
  * @return string  The new password on success.
  * @throws Horde_Auth_Exception
  */
 public function resetPassword($userId)
 {
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     /* Build the SQL query. */
     $query = str_replace(array('\\L', '\\P'), array($this->_db->quote($userId), $this->_db->quote(Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], $this->_params['show_encryption']))), $this->_params['query_resetpassword']);
     try {
         $this->_db->update($query);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Auth_Exception($e);
     }
     return $password;
 }
示例#2
0
文件: Ldap.php 项目: raz0rsdge/horde
 /**
  * Reset a user's password. Used for example when the user does not
  * remember the existing password.
  *
  * @param string $userId  The user id for which to reset the password.
  *
  * @return string  The new password on success.
  * @throws Horde_Auth_Exception
  */
 public function resetPassword($userId)
 {
     if (!empty($this->_params['ad'])) {
         throw new Horde_Auth_Exception(__CLASS__ . ': Updating users is not supported for Active Directory.');
     }
     /* Search for the user's full DN. */
     try {
         $dn = $this->_ldap->findUserDN($userId);
     } catch (Horde_Exception_Ldap $e) {
         throw new Horde_Auth_Exception($e);
     }
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     /* Encrypt the new password */
     $entry = array('userpassword' => Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], 'true'));
     /* Set the lastchange field */
     $shadow = $this->_lookupShadow($dn);
     if ($shadow['shadowlastchange']) {
         $entry['shadowlastchange'] = floor(time() / 86400);
     }
     /* Update user entry. */
     try {
         $this->_ldap->modify($dn, array('replace' => $entry));
     } catch (Horde_Ldap_Exception $e) {
         throw new Horde_Auth_Exception($e);
     }
     return $password;
 }
示例#3
0
 /**
  * Reset a user's password. Used for example when the user does not
  * remember the existing password.
  *
  * @param string $userId  The user id for which to reset the password.
  *
  * @return string  The new password.
  * @throws Horde_Auth_Exception
  */
 public function resetPassword($userId)
 {
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     $this->updateUser($userId, $userId, array('password' => $password));
     return $password;
 }
示例#4
0
文件: Sql.php 项目: horde/horde
 /**
  * Reset a user's password. Used for example when the user does not
  * remember the existing password.
  *
  * @param string $userId  The user id for which to reset the password.
  *
  * @return string  The new password on success.
  * @throws Horde_Auth_Exception
  */
 public function resetPassword($userId)
 {
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     /* Build the SQL query. */
     $query = sprintf('UPDATE %s SET %s = ?', $this->_params['table'], $this->_params['password_field']);
     $values = array(Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], $this->_params['show_encryption']));
     if (!empty($this->_params['soft_expiration_field'])) {
         $query .= ', ' . $this->_params['soft_expiration_field'] . ' = ?';
         $values[] = $this->_calc_expiration('soft');
     }
     if (!empty($this->_params['hard_expiration_field'])) {
         $query .= ', ' . $this->_params['hard_expiration_field'] . ' = ?';
         $values[] = $this->_calc_expiration('hard');
     }
     $query .= sprintf(' WHERE %s = ?', $this->_params['username_field']);
     $values[] = $userId;
     try {
         $this->_db->update($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Auth_Exception($e);
     }
     return $password;
 }
示例#5
0
 /**
  */
 public function authResetPassword($userId)
 {
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     /* Update password in DB. */
     require_once __DIR__ . '/base.php';
     $result = $GLOBALS['folks_driver']->changePassword($password, $userId);
     if ($result instanceof PEAR_Error) {
         throw new Horde_Auth_Exception($result);
     }
     return $password;
 }