Ejemplo n.º 1
0
 /**
  * Formats a password using the current encryption.
  *
  * @param   string   $plaintext     The plaintext password to encrypt.
  * @param   string   $salt          The salt to use to encrypt the password. []
  *                                  If not present, a new salt will be
  *                                  generated.
  * @param   string   $encryption    The kind of password encryption to use.
  *                                  Defaults to md5-hex.
  * @param   boolean  $show_encrypt  Some password systems prepend the kind of
  *                                  encryption to the crypted password ({SHA},
  *                                  etc). Defaults to false.
  *
  * @return  string  The encrypted password.
  *
  * @since   11.1
  */
 public static function getCryptedPassword($plaintext, $salt = '', $encryption = 'md5-hex', $show_encrypt = false)
 {
     // Get the salt to use.
     $salt = UserHelper::getSalt($encryption, $salt, $plaintext);
     // Encrypt the password.
     switch ($encryption) {
         case 'md5-hex':
         default:
             $encrypted = $salt ? md5($plaintext . $salt) : md5($plaintext);
             return $show_encrypt ? '{MD5}' . $encrypted : $encrypted;
     }
 }