Answers for "how to hash password in php for password_verify to work"

PHP
7

php hash password

//hash password
$pass = password_hash($password, PASSWORD_DEFAULT);

//verify password
password_verify($password, $hashed_password); // returns true
Posted by: Guest on July-11-2020
1

php hash password

/* Include the database connection script. */
include 'pdo.php';

/* Username. */
$username = 'John';

/* Password. */
$password = 'my secret password';

/* Secure password hash. */
$hash = password_hash($password, PASSWORD_DEFAULT);

/* Insert query template. */
$query = 'INSERT INTO accounts (account_name, account_passwd) VALUES (:name, :passwd)';

/* Values array for PDO. */
$values = [':name' => $username, ':passwd' => $hash];

/* Execute the query. */
try
{
  $res = $pdo->prepare($query);
  $res->execute($values);
}
catch (PDOException $e)
{
  /* Query error. */
  echo 'Query error.';
  die();
}
Posted by: Guest on October-19-2020

Code answers related to "how to hash password in php for password_verify to work"

Browse Popular Code Answers by Language