Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-06-2012, 02:17 PM   PM User | #1
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
Activation not working

Hi,
i was wondering if anyone had any idea how to fix this problem im having? My problem is the activation part of the code its not working at all. If the member did not activate there account it will still let them login. Here is some info on how i have it in the database. In the database when the member creates an account, it will also create a generated activation code for that account. Also if the member activates there account it will set it to 0 in the database. Any help would be great thanks.
PHP Code:
require("db.php");
$submitted_user '';
$errormessage '';
if(!empty(
$_POST))
{
    
$query "SELECT id,user,password,salt,actnum FROM users WHERE user = :user";
    
$query_params = array(
    
':user' =>  $_POST['user']
    );
    try
    {
        
$stmt $db->prepare($query);
        
$result $stmt->execute($query_params);
    }
    catch(
PDOException $ex)
    {
        die(
"Failed to run query: " $ex->getMessage());
    }
    
$login_ok false;
    
$row $stmt->fetch();
    if(
$row)
    {
        
$check_password hash('sha256'$_POST['password'] . $row['salt']);
        if(
$check_password === $row['password'])
        {
            
$login_ok true;
        }
    }
    if( !
$login_ok ) {
        
$errormessage "User ID/password mismatch";
////////Activation code/////////////
        
} elseif( $row['actnum'] != ) {
        
$errormessage "Account not activated";
/////////////////////////////////////////////////////////
        
} else {
        unset(
$row['salt']);
        unset(
$row['password']);
        
$_SESSION['user'] = $row;
        
header("Location: users");
    }
}
$submitted_user htmlentities($_POST['user'], ENT_QUOTES'UTF-8'); 
ycpc55 is offline   Reply With Quote
Old 08-06-2012, 02:32 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Is 'actnum' a string?

PHP Code:
elseif( $row['actnum'] != '0' 
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
ycpc55 (08-06-2012)
Old 08-06-2012, 04:52 PM   PM User | #3
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
Thanks a lot for your help works great now.
ycpc55 is offline   Reply With Quote
Old 08-06-2012, 04:53 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
In which case..

$check_password = $hash;

PHP statements are semi-colon terminated.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:43 AM.


Advertisement
Log in to turn off these ads.