Jump to content

Need help checking user account


bytesize

Recommended Posts

This code logs the user in with the correct user_email, user_pwd, and active=1.

A '0' is inserted into the active column of the users table during registration.

I need help checking if active=0 then flash_warning('User account not activated').

 

login_user.php

<?php
include(MODEL_PATH.'user.php');

switch ($route['view']){

case "login_user":
if(login($params['user']['user_email'], $params['user']['user_pwd']))
{
	flash_notice('You are logged in!');
	redirect_to('');
}
else
{
	flash_warning('Username or password is invalid!');
	$route['view'] = 'login';
}
break;
}

user.php

<?php
session_start();	

function login($username, $password)
{
db_connect_posts();

$query = sprintf("SELECT * FROM users
	WHERE 
		user_email = '%s' AND
		user_pwd = '%s' AND 
		active = '1'"
		, mysql_real_escape_string($username),
			md5($password)
		);

$result = mysql_query($query);

$number_of_posts = mysql_num_rows($result);

if($number_of_posts == 0)
{
	return false;
}

$row = mysql_fetch_array($result);

$_SESSION['user'] = $row;

return true;							
}
?>

Login form

<form action="<?php echo '/'.APP_ROOT.'/'; ?>sessions/login_user" method="post">
<fieldset>
  <legend>Login</legend>
  <div>
    <label>E-mail</label>
    <input name="user[user_email]" size="40" type="text" />
  </div>
  
  <div>
    <label>Password</label>
    <input name="user[user_pwd]" size="40" type="password" />
  </div>
  <input type="submit" value="Login" />
</fieldset>
</form>

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.