Skip to content

Instantly share code, notes, and snippets.

@cp-vrkansagara
Created September 7, 2020 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cp-vrkansagara/f68801bb1788b0d2897f3c247aaff637 to your computer and use it in GitHub Desktop.
Save cp-vrkansagara/f68801bb1788b0d2897f3c247aaff637 to your computer and use it in GitHub Desktop.
<?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