예제 #1
0
function take_registration_form()
{
    /**
     * $username string
     * $password string
     * $passhash_md5 string
     * $email string
     */
    $username = $_POST['login']['username'];
    $password = $_POST['login']['password'];
    $passhash_md5 = hash_password($password);
    $email = $_POST['login']['email'];
    /** 
     * Tarkasta annetun datan aitous ja ainutlaatuisuus
     * $email string
     * $password string
     * $username string
     */
    if (validate($email, $password, $username)) {
        echo "validaatio toimii";
        add_new_user($email, $passhash_md5, $username);
        $_SESSION['login']['passhash_md5'] = $passhash_md5;
        $_SESSION['login']['email'] = $email;
        $_SESSION['login']['logged_in'] = 1;
        $_SESSION['login']['user_id'] = get_user_id($email);
        $_SESSION['login']['username'] = $username;
        direct_right();
    } else {
        direct_wrong();
    }
}
예제 #2
0
/** 
 * Tarkasta annetun datan aitous ja ainutlaatuisuus
 * @param $email string 
 * @param $password string
 */
function take_login_form($password, $email)
{
    $passhash_md5 = md5($password);
    /** Tarkasta annetun datan aitous ja ainutlaatuisuus
     */
    if (validate($email, $password)) {
        echo "Validaation works";
        /**
         * $passhash_original string
         * $passhash_md5 string
         */
        $passhash_original = get_passhash_for_email($email);
        if (verify_passhash_for_email($passhash_md5, $passhash_original)) {
            echo "Verification works";
            // save data to sessions
            $_SESSION['login']['passhash_md5'] = $passhash_md5;
            $_SESSION['login']['email'] = $email;
            $_SESSION['login']['logged_in'] = 1;
            $_SESSION['login']['user_id'] = get_user_id($email);
            $_SESSION['login']['username'] = get_username($email);
            direct_right();
        } else {
            echo "Wrong password given.";
            direct_wrong();
        }
    } else {
        direct_wrong();
    }
}