-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.php
65 lines (53 loc) · 2.17 KB
/
auth.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
<?php
session_start();
require("database.php");
if (isset($_POST['register']))
{
$username = mysqli_escape_string($db,$_POST['username']);
$name = mysqli_escape_string($db,$_POST['name']);
$email = mysqli_escape_string($db,$_POST['email']);
$phone = mysqli_escape_string($db,$_POST['phone']);
$password = mysqli_escape_string($db,$_POST['password']);
$confirm_password = mysqli_escape_string($db,$_POST['confirm_password']);
if ($password==$confirm_password)
{
$query = "SELECT * FROM users WHERE username='$username'";
$res = mysqli_query($db, $query);
$row = mysqli_fetch_array($res);
$sameusers = mysqli_num_rows($res);
if ($sameusers==0)
{
$password = md5(sha1(crypt($password,10)));
$query = "INSERT INTO users(username, name, email, phone_no, password, usertype) VALUES('$username', '$name', '$email', '$phone', '$password', 'student')";
$res = mysqli_query($db, $query);
header ("Location:login.php?register=success");
}
else header ("Location:register.php?error=userexists");
}
else header ("Location:register.php?error=password_mismatch");
}
if (isset($_POST['login']))
{
$username = mysqli_escape_string($db,$_POST['username']);
$password = mysqli_escape_string($db,$_POST['password']);
$password = md5(sha1(crypt($password,10)));
$query = "SELECT * FROM users where username='$username' and password='$password'";
$res = mysqli_query($db, $query);
$row = mysqli_fetch_array($res);
$sameusers = mysqli_num_rows($res);
if ($sameusers==1)
{
$login_success = 1;
$_SESSION['userid']=$row['userid'];
$_SESSION['username']=$row['username'];
$_SESSION['name']=$row['name'];
$_SESSION['email']=$row['email'];
$_SESSION['phone_no']=$row['phone_no'];
$_SESSION['usertype']=$row['usertype'];
if ($_SESSION['usertype']=="student") header("Location:student.php");
if ($_SESSION['usertype']=="manager") header("Location:manager.php");
if ($_SESSION['usertype']=="admin") header("Location:admin.php");
}
else header("Location:login.php?error=invalid_details");
}
?>