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

Commit 9494b17

Browse files
gsmanu007ngsankha
authored andcommitted
Check for keys in $_POST array
Login and registering new users issues improved
1 parent 5b09990 commit 9494b17

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

login.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +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) ? trim($_POST['username']) : null;
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+
}
1718
else {
1819
// code to login the user and start a session
1920
connectdb();
@@ -29,9 +30,12 @@
2930
}
3031
} else if($_POST['action']=='register') {
3132
// register the user
32-
$email = mysql_real_escape_string($_POST['email']);
33-
if(trim($username) == "" or trim($_POST['password']) == "" or trim($email) == "")
34-
header("Location: login.php?derror=1"); // empty entry
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+
}
3539
else {
3640
// create the entry in the users table
3741
connectdb();
@@ -42,7 +46,7 @@
4246
else {
4347
$salt = randomAlphaNum(5);
4448
$hash = crypt($_POST['password'], $salt);
45-
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('".$username."', '$salt', '$hash', '".$email."')";
49+
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email`, `status` ) VALUES ('".$username."', '$salt', '$hash', '".$email."', '1')";
4650
mysql_query($sql);
4751
header("Location: login.php?registered=1");
4852
}

0 commit comments

Comments
 (0)