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

Commit

Permalink
uniform formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ngsankha committed May 2, 2016
1 parent 9494b17 commit 048e7ca
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
if(loggedin())
header("Location: index.php");
else if(isset($_POST['action'])) {
$username = array_key_exists('username', $_POST) ? trim($_POST['username']) : null;
$username = array_key_exists('username', $_POST) ? mysql_real_escape_string(trim($_POST['username'])) : "";
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 {
} else {
// code to login the user and start a session
connectdb();
$query = "SELECT salt,hash FROM users WHERE username='".$username."'";
Expand All @@ -30,20 +29,17 @@
}
} else if($_POST['action']=='register') {
// register the user
//$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 {
$email = array_key_exists('email', $_POST) ? mysql_real_escape_string(trim($_POST['email'])) : "";
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();
$query = "SELECT salt,hash FROM users WHERE username='".$username."'";
$result = mysql_query($query);
if(mysql_num_rows($result)!=0)
if(mysql_num_rows($result)!=0) {
header("Location: login.php?exists=1");
else {
} else {
$salt = randomAlphaNum(5);
$hash = crypt($_POST['password'], $salt);
$sql="INSERT INTO `users` ( `username` , `salt` , `hash` , `email`, `status` ) VALUES ('".$username."', '$salt', '$hash', '".$email."', '1')";
Expand Down

0 comments on commit 048e7ca

Please sign in to comment.