Skip to content

Instantly share code, notes, and snippets.

@caseysoftware
Last active October 1, 2015 04:48
Show Gist options
  • Select an option

  • Save caseysoftware/1923307 to your computer and use it in GitHub Desktop.

Select an option

Save caseysoftware/1923307 to your computer and use it in GitHub Desktop.
Code to generate the password
function user_login($username, $submitted) {
/**
* Retrieve the temporary/one-time password. While session-based is ok for
* this proof of concept, to make this more secure we'd want to use a database
* some sort of timeout to expire the password of N minutes/hours.
*/
$stored = $_SESSION['password'];
// Compare the retrieved vs the stored password
if ($stored == $submitted) {
$message = "Hello and welcome back $username";
} else {
$message = "Sorry, that's an invalid username and password combination.";
}
// Clean up after ourselves
unset($_SESSION['username']);
unset($_SESSION['password']);
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment