Click here to Skip to main content
16,010,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php
$msg = "";
if(isset($_POST['login'])) {
$username = stripcslashes($_POST['username']);
$password = $_POST['password'];
if($username != "" && $password != "") {
try {
//SELECT username,password FROM User WHERE username='$username' AND password='$password');
//$this->result = $this->sql->prepare('SELECT username,password FROM User WHERE username='$username' AND password='$password');
$query=( " SELECT username, password FROM users WHERE $username = 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 ($user && password_verify($_POST['pass'], $user['pass']))
if( $user && password_verify($_POST['pass'], $user['pass'])) { //i got this from the php website
header('location:we.php');
$_SESSION['username'] = $row['username'];
$_SESSION['name'] = $row['name'];

} else {
$msg = "Invalid login credentials";
}
} catch (PDOException $e) {
echo "Error : ".$e->getMessage();
}
} else {
$msg = "Both fields are required!";
}
}
?>

What I have tried:

Script modifications and a lot of research
Posted
Updated 8-Apr-20 5:05am

1 solution

Don't do that!
Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] - the code is C#, but it's pretty obvious.

And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
 
Share this answer
 
Comments
gavin_daCEO 9-Apr-20 6:48am    
I hash my passwords actually maybe it is the query that i did not build correctly . but i do hash them

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900