Answer the question
In order to leave comments, you need to log in
How to encrypt in such a way as to check the correctness of the password set?
There is this hash:
$SHA$a4e922231b027350$56a919d1e1445f19e7da5fa10facba24583a4e1d21cce99e1353d99526988024
Answer the question
In order to leave comments, you need to log in
We need to know the encryption algorithm.
Typical way:
//Сам пароль
$password = 'kernel_panic_is_not_1337';
//Хешируем первоначальный пароль
$hash1 = sha1($password);
//Генерируем случайный набор символов (соль)
$salt = 'salt_string_can_be_strong_and_hard_as_steel';
//Складываем старый хеш с солью и пропускаем через функцию sha1()
$hash2 = sha1($hash1 . $salt);
//Сравниваем полученный хэш с хранимым хэшем
if (hash2 == hash_from_db) {
echo ('success');
} else { echo ('fail');}
Hash is not encryption. To get the same hash, you need to know how it is obtained.
Don't reinvent the wheel. There have been reliable features for a long time.
password_hash
password_verify
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question