|
10 | 10 | if(loggedin()) |
11 | 11 | header("Location: index.php"); |
12 | 12 | else if(isset($_POST['action'])) { |
13 | | - $username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null; |
| 13 | + $username = array_key_exists('username', $_POST) ? mysql_real_escape_string(trim($_POST['username'])) : ""; |
14 | 14 | if($_POST['action']=='login') { |
15 | | - if(trim($username) == "" or trim($_POST['password']) == ""){ |
| 15 | + if(trim($username) == "" or trim($_POST['password']) == "") { |
16 | 16 | header("Location: login.php?derror=1"); // empty entry |
17 | | - } |
18 | | - else { |
| 17 | + } else { |
19 | 18 | // code to login the user and start a session |
20 | 19 | connectdb(); |
21 | 20 | $query = "SELECT salt,hash FROM users WHERE username='".$username."'"; |
|
30 | 29 | } |
31 | 30 | } else if($_POST['action']=='register') { |
32 | 31 | // register the user |
33 | | - //$email = mysql_real_escape_string($_POST['email']); |
34 | | - $username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null; |
35 | | - $email = array_key_exists('email', $_POST) ? trim($_POST['email']) : null; |
36 | | - if(trim($username) == "" and trim($_POST['password']) == "" and trim($email) == ""){ |
37 | | - header("Location: login.php?derror=1"); // empty entry\ |
38 | | - } |
39 | | - else { |
| 32 | + $email = array_key_exists('email', $_POST) ? mysql_real_escape_string(trim($_POST['email'])) : ""; |
| 33 | + if(trim($username) == "" and trim($_POST['password']) == "" and trim($email) == "") { |
| 34 | + header("Location: login.php?derror=1"); // empty entry |
| 35 | + } else { |
40 | 36 | // create the entry in the users table |
41 | 37 | connectdb(); |
42 | 38 | $query = "SELECT salt,hash FROM users WHERE username='".$username."'"; |
43 | 39 | $result = mysql_query($query); |
44 | | - if(mysql_num_rows($result)!=0) |
| 40 | + if(mysql_num_rows($result)!=0) { |
45 | 41 | header("Location: login.php?exists=1"); |
46 | | - else { |
| 42 | + } else { |
47 | 43 | $salt = randomAlphaNum(5); |
48 | 44 | $hash = crypt($_POST['password'], $salt); |
49 | 45 | $sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email`, `status` ) VALUES ('".$username."', '$salt', '$hash', '".$email."', '1')"; |
|
0 commit comments