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:

  1. create field in database password has type, sha256 or bcrypt
  2. upon login, verify password using type in database
  3. if sha256 , successful, create new bcrypt entry using entered password, store , update password type bcrypt. on next login, bcrypt used verification.

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -