Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$continue = "y";
while (($continue == 'y' || $continue == 'Y') == true) {
echo 'Enter username :- ';
$usernme = trim(fread(STDIN, 40));
echo 'Enter password :- ';
$password = trim(fread(STDIN, 40));
$options = [
'cost' => 12 // the default cost is 10
];
echo 'Please confirm password :- ';
$passwordAsk = trim(fread(STDIN, 40));
$hash = password_hash($passwordAsk, PASSWORD_DEFAULT, $options);
if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) {
// the password needs to be rehashed as it was not generated with
// the current default algorithm or not created with the cost
// parameter 12
$hash = password_hash($passwordAsk, PASSWORD_DEFAULT, $options);
// don't forget to store the new hash!
}
if (password_verify($password, $hash)) {
echo 'Password match.';
} else {
echo 'Invalid password.';
}
echo 'Do you wanted to add more user(s) ? (Press Y or y for continue)';
$continue = trim(fgetc(STDIN));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment