Hi Everyone,
When I sign up for my website and use your typed in password. Everything works.
When a user changes their password from within their control panel, then logout, then log back in again with that same password. Everything works.
When you email a password to yourself (because you forgot it) and try to login with that password. My website does not want to allow the user to login. I'm not sure why. Thanks Everyone!
My php check login code when a user is signing in.
Below is my forgot password codePHP Code:<?php
session_start();
include"connect_to_mysql3.php";
$loggedinuser = $_SESSION["id"];
$name = $_SESSION["name"];
if (isset( $_POST['name'], $_POST['password'] )){
$name = $_POST['name'];
$password = $_POST['password'];
$name = mysql_real_escape_string($name);
$password = mysql_real_escape_string($password);
$password = sha1($password);
$password = substr($password, 0,15);
$sql_id = mysql_query("SELECT * FROM practice WHERE name='$name' AND password='$password'");
while($row = mysql_fetch_array($sql_id)){
$id = $row["id"];
}
$sql = ("SELECT id FROM practice WHERE name='$name' AND password='$password'");
//$password = sha1($password);
//$password = substr($password, 0,15);
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION["name"] = $name;
$_SESSION["id"] = $id;
header("location:heythere.php");
} else {
echo "Wrong Username and Password. <a href=\"http://whatsmyowncarworth.com/class-work/sign3/valchecklogin.php\">Click Here</a> to login";
}
}
?>
PHP Code:<?php
// connect to database
include"connect_to_mysql3.php";
$email = $_POST['email'];
$submit = $_POST['submit'];
if ($submit){
// check is email exists
$email_check = mysql_query("SELECT * FROM practice WHERE email='".$email."'");
$count = mysql_num_rows($email_check);
if ($count != 0){
// generate new password
$password = rand();
$password = sha1($password);
$password = substr($password, 0,15);
// update database with new password
mysql_query("UPDATE practice SET password='".$password."' WHERE email='".$email."'");
// send the password to the user
$subject = "Login Information";
$message = "Your password has been changed to $password ";
$from = "From: myemail@yahoo.com";
mail($email, $subject, $message, $from);
echo "Your new password has emailed to you.";
} else {
echo "The email does not exist";
}
}
?>



Reply With Quote




Bookmarks