Codice PHP:
if(!empty($_POST))
{
        
$errors = array();
        
$username trim($_POST["username"]);
        
$password trim($_POST["password"]);
    
        
//Perform some validation
        //Feel free to edit / change as required
        
if($username == "")
        {
            
$errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
        }
        if(
$password == "")
        {
            
$errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
        }
        
        
//End data validation
        
if(count($errors) == 0)
        {
            
//A security note here, never tell the user which credential was incorrect
            
if(!usernameExists($username))
            {
                
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
            }
            else
            {
                
$userdetails fetchUserDetails($username);
            
                
//See if the user's account is activation
                
if($userdetails["Active"]==0)
                {
                    
$errors[] = lang("ACCOUNT_INACTIVE");
                }
                else
                {
                    
//Hash the password and use the salt from the database to compare the password.
                    
$entered_pass generateHash($password,$userdetails["Password"]);

                    if(
$entered_pass != $userdetails["Password"])
                    {
                        
//Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing
                        
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
                    }
                    else
                    {
                      
// inserisco in un oggetto i valori dell'utente dopo che il login
                        // è andato a buon fine
                        
$loggedInUser = new loggedInUser();
                        
$loggedInUser->email $userdetails["Email"];
                        
$loggedInUser->user_id $userdetails["User_ID"];
                        
$loggedInUser->display_username $userdetails["Username"];
                        
                        
// Aggiorno l'ultima visita
                        
$loggedInUser->updateLastSignIn();
                        
                        
// inserisco il tutto nella sessione
                        
$_SESSION["userCakeUser"] = $loggedInUser;
                        
                        
// Eseguo il redirect
                        
header("Location: account.php");
                        die();
                      }
                }
            }
        }
    } 
e poi sotto c'è il form...