-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
executable file
·80 lines (78 loc) · 1.88 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include "config.php";
include "lib/password.php";
$nick = $_POST['nick'];
$password = $_POST['password'];
date_default_timezone_set ( 'Asia/Kolkata' );
$date = localtime();
$flag = false;
if($date[5]<START_YEAR){
echo "Contest Has not Started.<br>";
die();
}else if($date[5]>START_YEAR){
$flag = true;
}else if($date[4]<START_MONTH){
echo "Contest Has not Started.<br>";
die();
}else if($date[4]>START_MONTH){
$flag = true;
}else if($date[3]<START_DAY){
echo "Contest Has not Started.<br>";
die();
}else if($date[3]>START_DAY){
$flag = true;
}else if($date[2]<START_HOUR){
echo "Contest Has not Started.<br>";
die();
}else if($date[2]>START_HOUR){
$flag = true;
}else if($date[1]<START_MINUTES){
echo "Contest Has not Started.<br>";
die();
}else if($date[1]>START_MINUTES){
$flag = true;
}else{
$flag = true;
}
if($flag){
try{
$con = new PDO('mysql:dbname='.SQL_DB.';host='.SQL_HOST, SQL_USER, SQL_PASS);
//Check if Nick is Exists
$stmt = $con->prepare("SELECT password FROM registration where nick = ?");
$stmt->execute(array($nick));
$row = $stmt->fetch();
if(!$row){
echo "Invalid Nick<br>";
die();
}else{
//Verify Password
if(password_verify($password,$row[0])){
$_SESSION['nick'] = $nick;
$stmt2 = $con->prepare("SELECT * FROM game where nick = ?");
$stmt2->execute(array($nick));
$row2 = $stmt2->fetch();
if(!$row2){
$stmt3 = $con->prepare("INSERT INTO game (nick) VALUES (?)");
$stmt3->execute(array($nick));
$_SESSION['level'] = 1;
$_SESSION['score'] = 0;
}else{
$_SESSION['level'] = $row2['level'];
$_SESSION['score'] = $row2['score'];
}
echo "TRUE";
}else{
echo "Invalid Password";
die();
}
$con = null;
}
}catch(PDOException $ex){
echo "Error!: " . $ex->getMessage() . "<br/>";
die();
}
}else{
echo "Contest Has not Started.<br>";
die();
}
?>