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