Created
December 17, 2019 08:16
-
-
Save tranquangchau/5745c8a594ce10f82a6609e04478f020 to your computer and use it in GitHub Desktop.
script php basic check password first before run everything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$errorMsg = ""; | |
$validUser = false; | |
if(isset($_SESSION['firstlogin'])) { | |
$validUser = $_SESSION["firstlogin"] === true; | |
} | |
//$pass_has = password_hash("123456", PASSWORD_DEFAULT); | |
//echo $pass_has; //get password first | |
// die; | |
if(isset($_POST["sub"])) { | |
$pass_has = '$2y$10$zVju3gx3QLJuRUiOvyQvpuWNsJlq8IV3.0FLY9apM5KoypWIyyVKq'; | |
$validUser = password_verify($_POST["firstpassword"], $pass_has); | |
if(!$validUser) $errorMsg = "Invalid password."; | |
else $_SESSION["firstlogin"] = true; | |
} | |
if($validUser) { | |
//header("Refresh:0"); die(); | |
}else{ | |
echo '<form name="input" action="" method="post"> | |
<label for="firstpassword">Password:</label><input type="password" value="" id="firstpassword" name="firstpassword" /> | |
<div class="error">'.$errorMsg.'</div> | |
<input type="submit" value="login" name="sub" /> | |
</form>';die; | |
} | |
//can get $pass_has at here http://www.passwordtool.hu/php5-password-hash-generator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment