note 124255 deleted from function.crypt by cmb
| From: | cmb@php.net | Date: | Tue, 01 Oct 2019 07:35:15 +0000 |
| Subject: | note 124255 deleted from function.crypt by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212446@lists.php.net to get a copy of this message | ||
Note Submitter: jeantirampeba at gmail dot com
----
je voudrais avoir un aide pour la ligne de comparaison d'un mot de passe crypté et celui non
crypté.ça me renvoie toujours que le" Invalid username and password!"
MECI POUR VOTRE AIDE
<?php
$msg = "";
if(isset($_POST['submitBtnLogin']))
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
//$pass_crypt = crypt($password);
if($username != "" && $password != "")
try
{
$query = "select * from chambre where Matricule=:username and password=:password";
$stmt = $db->prepare($query);
$stmt->bindParam('username', $username, PDO::PARAM_STR);
$stmt->bindValue('password', $password, PDO::PARAM_STR);
$stmt->execute();
$count = $stmt->rowCount();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($count == 1 && !empty($row))
{
if (hash_equals($hashed_password, crypt($_POST['password'], $hashed_password)))
{
echo "Mot de passe correct !";
/******************** Your code ***********************/
$_SESSION['sess_user_id'] = $row['id'];
$_SESSION['sess_user_name'] = $row['username'];
$_SESSION['sess_name'] = $row['name'];
header("location: home.php");
}
else
{
echo'<script>alert("Invalid password!")</script>';
}
}
else
{
echo'<script>alert("Invalid username and password!")</script>';
}
}
catch (PDOException $e)
{
echo "Error : ".$e->getMessage();
}
}
else
{
$msg = "Both fields are required!";
}
?>