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

Fixed registering new user and login issues #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
if(loggedin())
header("Location: index.php");
else if(isset($_POST['action'])) {
$username = mysql_real_escape_string($_POST['username']);
$username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null;
if($_POST['action']=='login') {
if(trim($username) == "" or trim($_POST['password']) == "")
if(trim($username) == "" or trim($_POST['password']) == ""){
header("Location: login.php?derror=1"); // empty entry
}
else {
// code to login the user and start a session
connectdb();
Expand All @@ -29,9 +30,12 @@
}
} else if($_POST['action']=='register') {
// register the user
$email = mysql_real_escape_string($_POST['email']);
if(trim($username) == "" or trim($_POST['password']) == "" or trim($email) == "")
header("Location: login.php?derror=1"); // empty entry
//$email = mysql_real_escape_string($_POST['email']);
$username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null;
$email = array_key_exists('email', $_POST) ? trim($_POST['email']) : null;
if(trim($username) == "" and trim($_POST['password']) == "" and trim($email) == ""){
header("Location: login.php?derror=1"); // empty entry\
}
else {
// create the entry in the users table
connectdb();
Expand All @@ -42,7 +46,7 @@
else {
$salt = randomAlphaNum(5);
$hash = crypt($_POST['password'], $salt);
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email` ) VALUES ('".$username."', '$salt', '$hash', '".$email."')";
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email`, `status` ) VALUES ('".$username."', '$salt', '$hash', '".$email."', '1')";
mysql_query($sql);
header("Location: login.php?registered=1");
}
Expand Down