本文整理汇总了PHP中crypt函数的典型用法代码示例。如果您正苦于以下问题:PHP crypt函数的具体用法?PHP crypt怎么用?PHP crypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了crypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPasswordForUser
public static function checkPasswordForUser($password, UserEntity $user)
{
if (hash_equals($user->getPassword(), crypt($password, $user->getPassword()))) {
return true;
}
return false;
}
示例2: login
public function login($username, $password)
{
# Check dependencies
self::dependencies(isset($this->settings, $username, $password));
# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());
# Check login with MD5 hash
if ($username === $this->settings['username'] && $password === $this->settings['password']) {
$_SESSION['login'] = true;
return true;
}
# Check login with crypted hash
if ($username === $this->settings['username'] && $this->settings['password'] === crypt($password, $this->settings['password'])) {
$_SESSION['login'] = true;
return true;
}
# No login
if ($this->settings['username'] === '' && $this->settings['password'] === '') {
$_SESSION['login'] = true;
return true;
}
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
return false;
}
示例3: addUser
public function addUser()
{
$username = $this->input->post('username');
$query = 'INSERT INTO users (username, name, email, password, created_at, updated_at)
VALUES(?, ?, ?, ? ,NOW(), NOW())';
return $this->db->query($query, array($username, $this->input->post('name'), $this->input->post('email'), crypt($this->input->post('pword'), "SecretSaltyGoodness23")));
}
示例4: guardar
public function guardar()
{
$arrayprivilegios = $this->input->post('privilegios');
$usuario = new Usuario($this->input->post('idusuario'));
$password = $this->input->post('password');
if ($usuario->exists()) {
if (!empty($password)) {
$usuario->password = crypt($password, 'mr%fsdfOk5ad');
}
} else {
$usuario->password = crypt($password, 'mr%fsdfOk5ad');
}
$usuario->usuario = $this->input->post('usuario');
$usuario->email = $this->input->post('email');
$usuario->save();
//guardamos los privilegios...
$privilegios = new Privilegio();
$privilegios->get();
$usuario->delete($privilegios->all);
//borramos todos...
foreach ($arrayprivilegios as $idprivilegio) {
$privilegio = new Privilegio($idprivilegio);
$usuario->save($privilegio);
}
redirect('admin/usuarios/listado');
}
示例5: ADODB_Session_Key
function ADODB_Session_Key()
{
$ADODB_CRYPT_KEY = 'CRYPTED ADODB SESSIONS ROCK!';
/* USE THIS FUNCTION TO CREATE THE ENCRYPTION KEY FOR CRYPTED SESSIONS */
/* Crypt the used key, $ADODB_CRYPT_KEY as key and session_ID as SALT */
return crypt($ADODB_CRYPT_KEY, session_ID());
}
示例6: authenticate
/**
* @param string $secret
* @param int $code
* @return bool
*/
public function authenticate($secret, $code)
{
$correct = false;
for ($i = -1; $i <= 1; $i++) {
if ($this->calculateCode($secret) == $code) {
$correct = true;
break;
}
}
// If they're not using a cache to prevent people being able to use the same code twice or if they were wrong anyway...
if (!isset($this->cachePool) || $correct == false) {
return $correct;
}
// If we're here then we must be using a cache, and we must be right
// We generate the key as securely as possible, then salt it using something that will always be replicatable.
// We're doing this hashing for de-duplication (aka, we want to know if it exists), but as we're also possibly
// securing the secret somewhere, we want to try and have as secure as possible
//
// If someone has any better suggestions on how to achieve this, please send in a PR! :P
$key = crypt($secret . "|" . $code, md5($code));
// If it existed, then we want this function to return false
if ($this->cachePool->hasItem($key)) {
return false;
}
// If it didn't, then we want this function to add it to the cache
// In PSR-6 getItem will always contain an CacheItemInterface and that seems to be the only way to add stuff
// to the cachePool
$item = $this->cachePool->getItem($key);
// It's a quick expiry thing, 30 seconds is more than long enough
$item->expiresAfter(new \DateInterval("PT30S"));
// We don't care about the value at all, it's just something that's needed to use the caching interface
$item->set(true);
$this->cachePool->save($item);
return true;
}
示例7: hash_pwd
function hash_pwd($pwd)
{
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
$salt = sprintf("\$2a\$%02d\$", 10) . $salt;
$hash = crypt($pwd, $salt);
return $hash;
}
示例8: check
public static function check($input, $stored_hash)
{
if (version_compare(PHP_VERSION, '5.3') < 0) {
throw new Exception("Bcrypt requires PHP 5.3 or above");
}
return crypt($input, $stored_hash) == $stored_hash;
}
示例9: encrypt
/**
* Encrypt value
*
* @param string $value
* @param string $salt Salt or crypted hash
* @return string
*/
public function encrypt($value, $salt = null)
{
if ($value instanceof Fs_File) {
$value = $value->getContents();
}
$value .= $this->secret;
switch (strtolower($this->method)) {
case null:
case 'crypt':
return crypt($value, $salt);
case 'std_des':
if (!CRYPT_STD_DES) {
throw new Exception("Unable to encrypt value: Standard DES-based encryption with crypt() not available.");
}
return crypt($value, isset($salt) ? substr($salt, 0, 2) : $this->makesalt(2));
break;
case 'ext_des':
if (!CRYPT_EXT_DES) {
throw new Exception("Unable to encrypt value: Extended DES-based encryption with crypt() not available.");
}
return crypt($value, isset($salt) ? $salt : $this->makesalt(9));
case 'md5':
if (!CRYPT_MD5) {
throw new Exception("Unable to encrypt value: MD5 encryption with crypt() not available.");
}
return crypt($value, isset($salt) ? $salt : $this->makesalt(12));
case 'blowfish':
if (!CRYPT_BLOWFISH) {
throw new Exception("Unable to encrypt value: Blowfish encryption with crypt() not available.");
}
return crypt($value, isset($salt) ? $salt : $this->makesalt(29));
default:
throw new Exception("Unable to encrypt value: Unknown crypt method '{$this->method}'");
}
}
示例10: isValidUser
public function isValidUser($userName, $password)
{
$user = $this->getByUsername($userName);
if (is_null($user)) {
return null;
}
$savedPassword = $user->getField($this->getUserTable()->password);
$validatedUser = null;
if ($savedPassword === AUTH_PASSWORD_NOT_CACHED) {
return null;
}
if ($this->passwordIsLegacyHash($savedPassword)) {
if ($savedPassword === md5($password . $this->_siteSalt) || $savedPassword === md5($password) || $savedPassword === md5(addslashes($password) . $this->_siteSalt) || $savedPassword === md5(addslashes($password))) {
$validatedUser = $user;
}
} else {
if (!function_exists('crypt')) {
throw new ErrorException("Crypt must be loaded for password_verify to function");
}
$ret = crypt($password, $savedPassword);
if (!is_string($ret) || strlen($ret) != strlen($savedPassword) || strlen($ret) <= 13) {
return null;
}
$status = 0;
$lenRet = strlen($ret);
for ($i = 0; $i < $lenRet; $i++) {
$status |= ord($ret[$i]) ^ ord($savedPassword[$i]);
}
if ($status === 0) {
$validatedUser = $user;
}
}
return $validatedUser;
}
示例11: verify
public static function verify($str, $hash)
{
if ($hash == crypt($str, $hash)) {
return true;
}
return false;
}
示例12: authenticate
/**
* Authenticates the password with the users current password.
*
* @param string $password
*
* @return boolean
*/
public function authenticate($password)
{
if ($this->password_ver == 'crypt') {
return $this->password === crypt($password, $this->password);
} else {
}
}
示例13: validate
public function validate($strPlainText, $strHash)
{
if (CRYPT_SHA512 != 1) {
throw new Exception('Hashing mechanism not supported.');
}
return crypt($strPlainText, $strHash) == $strHash ? true : false;
}
示例14: encrypt
/**
* Encrypts the data
* @param string $data
* @return string
* @throws \InvalidArgumentException
* @see hash()
*/
public function encrypt($data)
{
if (!is_string($data)) {
throw new \InvalidArgumentException('data');
}
return crypt($data, $this->getSalt());
}
示例15: authenticate
function authenticate($username, $password)
{
$encrypted_old = md5($password);
$row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username), true);
if ($row['username'] && $row['username'] == $username) {
// Migrate from old, unhashed password
if ($row['password'] == $encrypted_old) {
$row_type = dbFetchRow('DESCRIBE users password');
if ($row_type['Type'] == 'varchar(34)') {
changepassword($username, $password);
}
return 1;
} else {
if (substr($row['password'], 0, 3) == '$1$') {
$row_type = dbFetchRow('DESCRIBE users password');
if ($row_type['Type'] == 'varchar(60)') {
if ($row['password'] == crypt($password, $row['password'])) {
changepassword($username, $password);
}
}
}
}
$hasher = new PasswordHash(8, false);
if ($hasher->CheckPassword($password, $row['password'])) {
return 1;
}
}
//end if
return 0;
}