Esempio n. 1
0
<?php

$parts = explode('@', $_POST[email]);
if (filter_var($_POST[email], FILTER_VALIDATE_EMAIL) && $parts[1] == 'rpi.edu') {
    if (strlen($_POST[password]) >= 6 && strlen($_POST[password]) <= 16) {
        require '../../../global_assets/global_php/connect.php';
        require '../../../global_assets/global_php/hashFunctions.php';
        $query = mysql_query('SELECT `password`, `valid`, `rin` FROM `users` WHERE `email`="' . mysql_real_escape_string($_POST[email]) . '" LIMIT 1');
        if (mysql_num_rows($query) == 1) {
            $results = mysql_fetch_array($query);
            if (passwordsMatch($results[password], $_POST[password])) {
                if (strlen($results[valid]) == 0) {
                    setcookie('userId', $results[rin], time() + 60 * 60 * 24 * 365, '/', '.foosrpi.com');
                    echo 'success';
                    exit;
                } else {
                    echo 'You must first validate your email to sign in.';
                    exit;
                }
            }
        }
    }
}
echo 'Email or password incorrect.';
Esempio n. 2
0
<?php 
if (isset($_POST['submit'])) {
    $password1 = null;
    $password2 = null;
    if (isset($_POST['password1']) && isset($_POST['password2'])) {
        $password1 = $_POST['password1'];
        $password2 = $_POST['password2'];
    }
    $username = $_POST['username'];
    $newPassword = $password1;
    if ($username == '') {
        echo 'Please specify a username\\n';
    }
    meetsPasswordLength($password1, true);
    passwordsMatch($password1, $password2, true);
    if (meetsPasswordLength($password1, false) && passwordsMatch($password1, $password2, false) && $username !== '') {
        $hash = password_hash($newPassword, PASSWORD_DEFAULT);
        $query = "UPDATE users SET hash = :hash WHERE username LIKE :username";
        $result = getDB()->prepare($query);
        $result->bindParam(':hash', $hash);
        $result->bindParam(':username', $username);
        $result->execute();
        echo 'Password for ' . $username . ' changed';
    }
}
?>
</body>
</html>


Esempio n. 3
0
<?php

include "db.php";
if (isset($_POST['submit'])) {
    $username = $_POST['username-reg'];
    $password = $_POST['password-reg'];
    $rptPassword = $_POST['password-repeat-reg'];
    $email = $_POST['email-reg'];
    $date = new DateTime();
    $date = $date->format('y-m-d');
    if (passwordsMatch($password, $rptPassword) && registerUser($username, $password, $email, $date)) {
        session_start();
        $_SESSION['username'] = $username;
        header("Location: ../home.php");
    }
}
function passwordsMatch($pass, $rptPass)
{
    return $pass == $rptPass;
}