Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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'); 

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • Users who have thanked AndrewGSW for this post:

    ycpc55 (08-06-2012)

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks a lot for your help works great now.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •