PHP password hash generator code example
Example 1: hash a password php
password_hash("MySuperSafePassword!", PASSWORD_DEFAULT)
password_verify("MySuperSafePassword!", $hashed_password)
Example 2: online password generator in php
<?php
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
echo randomPassword();
?>
Example 3: php hash password
$password = 'my secret password';
$hash = password_hash($password, PASSWORD_DEFAULT);
Example 4: password_hash
<?php
$password = 'idkWhatToUse';
$hashedPassword= password_hash($password, PASSWORD_DEFAULT);
?>
Example 5: php hash password
include 'pdo.php';
$username = 'John';
$password = 'my secret password';
$hash = password_hash($password, PASSWORD_DEFAULT);
$query = 'INSERT INTO accounts (account_name, account_passwd) VALUES (:name, :passwd)';
$values = [':name' => $username, ':passwd' => $hash];
try
{
$res = $pdo->prepare($query);
$res->execute($values);
}
catch (PDOException $e)
{
echo 'Query error.';
die();
}
Example 6: php hash password
<?php
echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT);
?>