Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit d818e13

Browse files
committed
t push origin masterMerge branch 'gsmanu007-master'
2 parents 5b09990 + 048e7ca commit d818e13

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

login.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
if(loggedin())
1111
header("Location: index.php");
1212
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'])) : "";
1414
if($_POST['action']=='login') {
15-
if(trim($username) == "" or trim($_POST['password']) == "")
15+
if(trim($username) == "" or trim($_POST['password']) == "") {
1616
header("Location: login.php?derror=1"); // empty entry
17-
else {
17+
} else {
1818
// code to login the user and start a session
1919
connectdb();
2020
$query = "SELECT salt,hash FROM users WHERE username='".$username."'";
@@ -29,20 +29,20 @@
2929
}
3030
} else if($_POST['action']=='register') {
3131
// 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) == "") {
3434
header("Location: login.php?derror=1"); // empty entry
35-
else {
35+
} else {
3636
// create the entry in the users table
3737
connectdb();
3838
$query = "SELECT salt,hash FROM users WHERE username='".$username."'";
3939
$result = mysql_query($query);
40-
if(mysql_num_rows($result)!=0)
40+
if(mysql_num_rows($result)!=0) {
4141
header("Location: login.php?exists=1");
42-
else {
42+
} else {
4343
$salt = randomAlphaNum(5);
4444
$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')";
4646
mysql_query($sql);
4747
header("Location: login.php?registered=1");
4848
}

0 commit comments

Comments
 (0)