PDA

View Full Version : سوال: اشکال در login



سلمان رسولی
یک شنبه 14 فروردین 1390, 13:53 عصر
سلام
من php رو تازه شروع کردم و حرفه ای نیستم. برای login شدن این کد رو از یه سایتی گرفتم و تست کردم ولی وقتی user , pass رو وارد میکنم این پیغام داده میشه:Incorrect password, please try again.
این همون کد یه که نوشتم:

<?php

// Connects to your Database
mysql_connect("localhost", "php", "php") or die(mysql_error());
mysql_select_db("shop") or die(mysql_error());
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: members.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
else
{
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header("Location: members.php");
}
}
}
else
{
// if they are not logged in
?>
<?php
}

?>

لطفا راهنمایی کنید:متفکر:

Keramatifar
دوشنبه 15 فروردین 1390, 11:55 صبح
دوست عزیز
اول مطمئن شوید که دیتابیس و جداول مورد نظر را بدرستی ایجاد کردید

mtchabok
دوشنبه 15 فروردین 1390, 12:49 عصر
عزیزم آیا در زمان عضویت پسورد رو md5 میکنی ؟

سلمان رسولی
دوشنبه 15 فروردین 1390, 21:48 عصر
بانک رو چک کردم مشکلی نداشت.
ولی md5 چی هست؟

sargardoon
سه شنبه 16 فروردین 1390, 00:58 صبح
بانک رو چک کردم مشکلی نداشت.
ولی md5 چی هست؟
شما اینجا از md5 استفاده کردید

$_POST['pass'] = md5($_POST['pass']);
برای مثال اگر مقدار
$_POST['pass'] = 123 باشه به اینصورت میشه

202cb962ac59075b964b07152d234b70

موفق باشید.

sargardoon
سه شنبه 16 فروردین 1390, 01:00 صبح
اگر میخواهید وارد بشید میتونی یه کلک سوار کنی
اون کدی که من بالا نوشتم رو بذار جای مقدار پسورد در دیتابیس بعد رمز شما میشه 123