<?PHP
date_default_timezone_set('UTC');
$nama1 = $_POST["n"];
$pass1 = $_POST["p"];
$pass1 = md5($pass1);
include("index.cma.login.db.php");
$query = "Select * from $mytable where user_name ='$nama1'";
$result = mysql_query($query); 
if ($row = mysql_fetch_array($result)){ 
if ($row[user_fail] <= 5){
if ($row[user_key] == $pass1){
$user_logindate1 = date("j/m/Y g:i A");
$actnum = "";
$chars_for_actnum = array ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z","1","2","3","4","5","6","7","8","9","0");
for ($i = 1; $i <= 20; $i++) {
$actnum = $actnum . $chars_for_actnum[mt_rand (0,62)];
}
$query = "UPDATE $mytable Set user_session = '$actnum', user_logindate = '$user_logindate1', user_fail = '0' where user_name ='$nama1'";  
$result = mysql_query($query); 
$query = "Select * from $mytable where user_name ='$nama1'"; 
$res1 = mysql_query("$query"); 
if($row = mysql_fetch_array($res1)){
$nama = "$row[user_name]";
header("Location: index.home.php?session=$actnum&name=$nama");
session_start();
$_SESSION['Nama'] = "$nama";
$_SESSION['Pass'] = "$actnum";
}
else{$datetime = date("d")*10000000000 + date("m")*100000000 + date("Y")*10000 + date("G")*100 + date("i");
if ($row[user_fail] >= ($datetime-5)){
$query = "UPDATE $mytable Set user_fail = user_fail + 1 where user_name ='$nama1'";  
$result = mysql_query($query); 
}else{
}
makeform("Login Gagal!");}
}
else {
$datetime = date("d")*10000000000 + date("m")*100000000 + date("Y")*10000 + date("G")*100 + date("i");
if ($row[user_lastloginfail] <= ($datetime-30)){
$query = "UPDATE $mytable Set user_fail = '5' where user_name ='$nama1'";  
$result = mysql_query($query); 
echo "Gagal Login, silahkan ulangi atau Hubungi admin untuk bantuan";
}else{
echo "Login terkunci"; }}}else{echo "Account belum aktif"; }}
else{if ($user_name == ""){	makeform("");}else {makeform("Login Gagal!!");}}
function makeform($errormessage){
?>
<title>Login</title>
<?PHP echo "$errormessage"; ?>
<?php  }?>
