How to migrate from sha256 encryption to bcrypt for php? -
for login :
$rows = $sql->fetch(pdo::fetch_assoc); $us_id = $rows['id']; $us_pass = $rows['password']; $us_salt = $rows['password_salt']; $status = $rows['attempt']; $saltedpass = hash('sha256', "{$password}{$this->passwordsalt}{$us_salt}");
for register :
$randomsalt = $this->rand_string(20); $saltedpass = hash('sha256', "{$password}{$this->passwordsalt}{$randomsalt}");
how can sha256 encryption method converted bcrypt ?
password hashing using bcrypt
if using php 5.5 or later, can use built-in password_hash()
function $algo
parameter set password_bcrypt
create bcrypt hashes. can use so:
$options = array('cost' => 11, 'salt' => 'my_salt'); $hash = password_hash("my_secret_password", password_bcrypt, $options);
migration
it's not possible bulk migration sha256 bcrypt because need original plaintext data (password) isn't available.
typically, sites staged conversion convert users perform successful logins. example:
- create field in database password has type, sha256 or bcrypt
- upon login, verify password using type in database
- if sha256 , successful, create new bcrypt entry using entered password, store , update password type bcrypt. on next login, bcrypt used verification.
Comments
Post a Comment