Jump to content

[SOLVED] Login script help


wrathican

Recommended Posts

hey guys im making a login script that does the following in this order:

1 checks to see if the username exsists

2 if the username exists, get the password from the db

3 compare the db pass and entered pass

4 if they match check to see if the account is activated

a if the account isnt activated it returns to some page with an error

b if the account is active it logs the person in using sessions

 

login script:

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$password = sha1($password);

$query = "SELECT user_username, user_password, user_level, user_active FROM ls12_users WHERE user_username='".$username."'";
$result = query($query);
$rows = numRows($result);

if($rows == 1) {
	$array = fetchArray($result);
	$username = $array['user_username'];
	$dbpassword = $array['user_password'];
	$level = $array['user_level'];
	$active = $array['user_active'];

	if ($password == $dbpassword) {
		//check if active
		if ($active == 1) {
			//the account is active. set sessions
			$_SESSION['username'] = $username;
			$_SESSION['level'] = $level;

			header('location: ../index.php');

		}else{
			//account is not active
			$_SESSION['errorstate'] = 1;
			$errorarray[] = "Sorry, but your account has not been activated yet. Please check your email for the activation email and follow the instructions there.";
			$_SESSION['errormessage'] = $errorarray;

			header('location: ../login.php');
		}
	}else{

		$_SESSION['errorstate'] = 1;
		$errorarray[] = "Sorry, but the password you entered was incorrect. Please try again.";
		$_SESSION['errormessage'] = $errorarray;

	header('location: ../login.php');

	}

}else{
	$_SESSION['errorstate'] = 1;
	$errorarray[] = "Sorry, but the username you entered does not exsist. Please try again.";
	$_SESSION['errormessage'] = $errorarray;

	header('location: ../login.php');
}
?>

 

functions.inc:

<?php

//queries the db
function query($query) {
mysql_query($query);
}

//gets an array based on the query
function fetchArray($result) {
mysql_fetch_array($result);
}

//get the number of rows from the query
function numRows($result) {
mysql_num_rows($result);
}

?>

 

i get this error "Sorry, but the username you entered does not exsist. Please try again." whihch means that the username i entered doesnt exsist in the db. however the username DOES actually exsist, any ideas why i am getting this error?

Link to comment
Share on other sites

their is three lines that you may need to change,

 

change your SQL to this:

$query = "SELECT `user_username`, `user_password`, `user_level`, `user_active` FROM l`s12_users` WHERE `user_username` = '".$username."'";

 

and change $row to:

$rows = mysql_num_rows($result);

 

and finally, change $array to:

$array = mysql_fetch_array($result);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.