Example #1
0
 function InsertDB($first_name, $last_name, $group, $email, $mark)
 {
     global $connection;
     $pass = hashed_password();
     if (!(is_null($first_name) && is_null($last_name) && is_null($group) && is_null($email) && is_null($mark))) {
         $query = "INSERT INTO abit ";
         $query .= "(firstname, lastname, groupname, mark, email, pass) ";
         $query .= "VALUES ('{$first_name}', '{$last_name}', '{$group}', '{$mark}', '{$email}', '{$pass}')";
         $result = $connection->query($query);
         confirm_query($result);
     }
 }
Example #2
0
function resetPassword($password)
{
    $conn = mysqli_connect(db_host, db_user, db_pass, db_name);
    if (mysqli_connect_errno()) {
        echo "Error connecting to database";
        return;
    }
    $user_id = $_SESSION['temp_user']['_user_id'];
    $salt = substr(str_replace('+', '.', base64_encode(md5(mt_rand(), true))), 0, 16);
    $hash = hashed_password($password, $salt);
    $query = "UPDATE users SET password = '******', salt = '" . $salt . "', token = null WHERE userid = '" . $user_id . "'";
    if ($conn->query($query) !== TRUE) {
        mysqli_close($conn);
        echo "Error connecting to database";
        return;
    }
    mysqli_close($conn);
    $isSuccess = true;
    echo "<script>parent.submit(" . $isSuccess . ");</script>";
}
Example #3
0
function register($user_name, $email, $user_pass)
{
    $err = '';
    $conn = mysqli_connect(db_host, db_user, db_pass, db_name);
    if (mysqli_connect_errno()) {
        echo '<script>$("#error_message").html("Server error: could not connect.");</script>';
        return;
    }
    $salt = substr(str_replace('+', '.', base64_encode(md5(mt_rand(), true))), 0, 16);
    $hash = hashed_password($user_pass, $salt);
    $query = "SELECT DISTINCT userid, username, email FROM users WHERE username = '******' OR email = '" . $email . "'";
    $query2 = "INSERT INTO users (username, email, password, salt) VALUES ('" . $user_name . "','" . $email . "','" . $hash . "','" . $salt . "')";
    $result = mysqli_fetch_assoc(mysqli_query($conn, $query));
    if ($result['userid'] == null || $result['userid'] == '') {
        $result2 = mysqli_query($conn, $query2);
        if ($result2) {
            mysqli_close($conn);
            login($user_name, $user_pass);
        } else {
            echo '<script>$("#error_message").html("Server error: Could not connect.");</script>';
            mysqli_close($conn);
        }
    } else {
        if ($email == null) {
            $err = 'You must enter a valid email';
        } else {
            if ($result['email'] == $email) {
                $err = 'A username is already registered under this email';
            } else {
                if ($result['username'] == $user_name) {
                    $err = 'Username ' . $user_name . ' not available';
                } else {
                    $err = 'An error occured';
                }
            }
        }
    }
    echo '<script>$("#error_message").html("' . $err . '");</script>';
    mysqli_close($conn);
}