Пример #1
0
/**
 * 
 * @param type $username
 * @param type $password
 * @return boolean
 */
function login($username, $password)
{
    $member_id = member_id_from_username($username);
    $username = trim($username);
    $password = sha1($password);
    $con = mysqli_connect(DB_SERVER, DBASE_USER, DBASE_PASS, DBASE_NAME);
    $sql = "SELECT * FROM member WHERE username = '******' AND password='******'";
    $query = mysqli_query($con, $sql);
    $data = mysqli_fetch_array($query, MYSQLI_NUM);
    if ($data[0] >= 1) {
        return TRUE;
    } else {
        return FALSE;
    }
}
Пример #2
0
/**
 * This function register users
 * @param type $username
 * @param type $email
 * @param type $password
 */
function register($username, $email, $password)
{
    $con = mysqli_connect(DB_SERVER, DBASE_USER, DBASE_PASS, DBASE_NAME);
    $usname = trim($username);
    $mail = trim($email);
    $pass = sha1(trim($password));
    $sql = "INSERT INTO member (username, email, password)VALUES ('{$usname}', '{$mail}', '{$pass}')";
    if (mysqli_query($con, $sql)) {
        echo "user created";
        //set username sessions
        $_SESSION['username'] = $username;
        //set password sessions
        $memberID = member_id_from_username($username);
        $_SESSION['memberID'] = $memberID;
        //send emal activatin code to the email
        send_email_activation_code($mail);
        //Redirect after user has been created
        header("Location: user_registered.php?mail={$email}");
    } else {
        die("Sorry an error occured" . mysql_error());
    }
    exit;
}
Пример #3
0
include 'config.php';
if (empty($_POST) === false) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    if (empty($username) === TRUE || empty($password) === TRUE) {
        $errors[] = 'You need to enter a username and password';
    } elseif (member_exists($username) === false) {
        $errors[] = 'Username does not exist. Please register';
    } elseif (member_active($username) === FALSE) {
        $errors[] = 'You account isn`t activated. An activation link was sent to your e-mail. Follow it';
    } else {
        $login = login($username, $password);
        if ($login === FALSE) {
            $errors[] = 'Username or password is in correct';
        } else {
            echo 'Success';
            // Set session variables
            $memberID = member_id_from_username($username);
            //set username session
            $_SESSION["username"] = $username;
            //set user id session
            $_SESSION["memberID"] = $memberID;
            //set user password session
            $_SESSION["password"] = $password;
            //redirect to dashbord
            header("location: dashboard.php");
        }
    }
    print_r($errors);
}