Being new to programming and php but eager to learn I quickly figured out that there are so called "best" and "bad" practices. Bad practice is the use of MD5 encryption for example which I was about to learn and implement. However, I just recently learned about the relatively new password_hash() function that automates a lot (yes, I did'nt use the word alot :D) of the process of encryption such as adding salt. Correct me if im wrong though.
So here I am with a question about how to correctly use this function.
function login_check() { $connection = database(); $name = $_POST['name']; $password = $_POST['password']; $password_hash = password_hash($password, PASSWORD_DEFAULT); $query = "SELECT id FROM users WHERE name = ? AND password = ?"; $stmt = mysqli_prepare($connection, $query); mysqli_stmt_bind_param($stmt, 'ss', $name, $password); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); $counter = mysqli_stmt_num_rows($stmt); if($counter > 0 && password_verify($name, $password_hash)){ $_SESSION['login'] = $name; header('location:../../index.php'); exit; } else { header('location:../../failed.php'); exit; } } if(isset($_POST['name']) && isset($_POST['password'])){ login_check(); } So this is how far I go and to be honest Im not sure if this is even the right way. Could need your feedback. Is this ok or are there any additional things to consider to make this work?
I read that there is no need to create own salt and other hash related things anymore.
password_hash()on the password you stored on the database? Sorry if this sounds like a silly question but it has to be asked!password_hash()on entered password , and thenpassword_verify()it with hash from database!