Jump to content

authentication problem


Recommended Posts

i got problem somewhere while trying to authenticate users while loging in. what i wrote to authenticate in classuser file is this--

	// start authentication	$safeUser = $mysqli->real_escape_string($username);	$incomingPass = $mysqli->real_escape_string($password);	$query = "SELECT * FROM user  WHERE username = '{$safeUser}'";		if (!$result = $mysqli->query($query)) {			error_log("Cannot retrieve account record for {$username}");			return false;		}	// no while loop for single row	$row = $result->fetch_assoc();	$dbPass = $row['password'];		if (crypt($incomingPass, $dbPass) !=  $dbPass) {			error_log("Wrong Password for {$username}!");			return false;		}

i've mysql table 'user' and columns 'username' & 'password'. while trying loging in with valid username & password also it gives username & password related error. both username & password are recorded in CHAR(10) type.....

Link to post
Share on other sites

thank u

 

i made it done with something different

		// start authentication		$username = $_POST['username'];		$password = $_POST['password'];		$query = "SELECT * FROM user  WHERE username = '{$username}'";		$result = mysqli_query($mysqli, $query);		if (!$result) {			error_log("Cannot retrieve account record for {$username}");			return false;		}		// no while loop for single row		$row = mysqli_fetch_array($result);		$dbPass = $row['password'];		$type = $row['type'];		$count = mysqli_num_rows($result);				if ($password == $dbPass && $type == "1") {				error_log("Welcome {$username}!");				return true;			}			else {				error_log("Wrong password!");				return false;			}		$this->uid = $row['uid'];		$this->name = $row['name'];		$this->username = $row['username'];		$this->password = $row['password'];		$this->type = $row['type'];		$this->isLoggedIn = true;		$this->_setSession();		return true;	}

but session couldn't be started. it failed load authenticated page when i added this line to top of it....

<?phprequire_once('functions.php');$user = new User;if (!$user->isLoggedIn) {	die(header("location: login.php"));}?>

and went back to login page.

Link to post
Share on other sites

sorry i couldnt understand what u suggested but below the authentication function there is session start function like this ---

	private function _setSession() {		if (session_id() == '') {			session_start();		}		$_SESSION['uid'] = $this->uid;		$_SESSION['name'] = $this->name;		$_SESSION['address'] = $this->address;		$_SESSION['phone'] = $this->phone;		$_SESSION['username'] = $this->username;		$_SESSION['password'] = $this->password;		$_SESSION['type'] = $this->type;		$_SESSION['isLoggedIn'] = $this->isLoggedIn;	} // end function setSession

and init user function like this

	private function _initUser() {		$this->uid = $_SESSION['uid'];		$this->name = $_SESSION['name'];		$this->address = $_SESSION['address'];		$this->phone = $_SESSION['phone'];		$this->username = $_SESSION['username'];		$this->password = $_SESSION['password'];		$this->type = $_SESSION['type'];		$this->isLoggedIn = $_SESSION['isLoggedIn'];	} // end function initUser
Link to post
Share on other sites

oh i did it. thank u for the company.

i changed

this--

if ($password == $dbPass && $type == "1") {	error_log("Welcome {$username}!");	return true;}else {	error_log("Wrong password!");	return false;		}

to--

		if ($password != $dbPass) {			error_log("Wrong password!");			return false;		}

and its done.

 

but i need one more help. this successful login redirects to admin.php (as i've defined on login-precess file). but i want to change the page to redirect to different pages according to user types. how can i do that? please guide...

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...