2021年3月26日星期五

How to encrypt the password using password_hash in php? [duplicate]

I want to encrypt the password and store it in the database but I do not really understand how to use password_hash. I had found some tutorials but it doesn't work.

The below is connnection.php

<?php      $conn = new mysqli("localhost","root","","mydata");      if (!$conn) {          die('Please Check your connection'/mysqli_error($conn));      }  ?>  

The below is login.php

<?php  require_once('connection.php');        $msg="";      if (isset($_POST['login'])) {          $username = $_POST['username'];          $password = $_POST['password'];          $password_encrypted = password_hash($password, PASSWORD_DEFAULT);            $sql = "SELECT * FROM login WHERE UserName=? AND Password=? ";          $stmt = $conn->prepare($sql);          $stmt->bind_param("ss",$username,$password_encrypted);          $stmt->execute();          $result =  $stmt->get_result();          $row = $result->fetch_assoc();            session_regenerate_id();          $_SESSION['username'] = $row['UserName'];          session_write_close();            if($result-> num_rows==1 && $_SESSION['username']=="admin")              {   header("location:home.php"); }          else{   $msg = "Username or Password is Incorrect!!!";}      }    ?>  
https://stackoverflow.com/questions/66795765/how-to-encrypt-the-password-using-password-hash-in-php March 25, 2021 at 04:36PM

没有评论:

发表评论