K
K
KRHD2015-10-23 06:01:48
PHP
KRHD, 2015-10-23 06:01:48

How to encrypt in such a way as to check the correctness of the password set?

There is this hash:

$SHA$a4e922231b027350$56a919d1e1445f19e7da5fa10facba24583a4e1d21cce99e1353d99526988024

How can I encrypt the password in the same format to verify for authorization?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikolai Trifonov, 2015-10-23
@fridriekh

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');}

V
Vladimir Martyanov, 2015-10-23
@vilgeforce

Hash is not encryption. To get the same hash, you need to know how it is obtained.

M
Mikhail Osher, 2015-10-23
@miraage

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 question

Ask a Question

731 491 924 answers to any question