Simplified user login authentication
PHP Code:
$user_name = mysql_real_escape_string($_POST['user_name']);
$user_password = mysql_real_escape_string($_POST['user_password']);
if you want to add more password security you can use hashing by using md5, the downside is, md5 is a one-way encryption procedure, it only ecrypt but it cant decrypt most website uses this type of encryption along side with adding salt to the parameter, in this way to retrieve the password you have to regenerate it again
PHP Code:
// With salt
$user_password = md5('salbahis-gwapo@'.$user_password);
// Without salt
$user_password = md5($user_password);
To make this query works MORE better, you have to make sure the table structure of user name are set to UNIQUE, or atleast all data save on that field are unique
PHP Code:
$res = mysql_query("SELECT TRUE AS is_exist FROM user_table WHERE username='".$user_name."' AND password='".$user_password."'");
$isfound = mysql_fetch_object($res);
if($isfound->is_exist){
// OK
}else{
// Not OK
}
or this one
PHP Code:
$res = mysql_query("SELECT COUNT(username) AS _count FROM user_table WHERE username='".$user_name."' AND password='".$user_password."'");
$user = mysql_fetch_object($res);
if($user->_count == 1){
// OK
}elseif($user->_count > 1){
// Duplicate username
}else{
// Not OK
}
and another one
PHP Code:
$res = mysql_query("SELECT username FROM user_table WHERE username='".$user_name."' AND password='".$user_password."'");
$num_rows = mysql_num_rows($res)
if($num_rows == 1){
// OK
}elseif($num_rows > 1){
// Duplicate username
}else{
// Not OK
}
dili kay simplified ang code sample ninyo so i made it simplified...