function googleLogin($connect, $name, $email)
{
    $id = getUserId($connect, $email);
    if ($id > 0) {
        updateLastLogin($connect, $id);
        $response = array();
        $response['status'] = 1;
        $response['message'] = "Successfully logged in";
        $response['user_id'] = $id;
        echo json_encode($response);
    } else {
        $code = createAccount($connect, $name, $email);
        if ($code == 1) {
            $response = array();
            $response['status'] = 5;
            $response['message'] = "Account Created Successfully";
            $response['user_id'] = getUserId($connect, $email);
            echo json_encode($response);
        } elseif ($code == 3) {
            showJson(3, "Email already registered\nLogin using email and password");
        } else {
            showJson(0, "Oops!...Details cannot be added into Database.Try again later.");
        }
    }
}
function normalLogin($connect, $email, $password)
{
    $id = checkCredentials($connect, $email, $password);
    if ($id > 0) {
        updateLastLogin($connect, $id);
        $response = array();
        $response['status'] = 1;
        $response['message'] = "Successfully logged in";
        $response['user_id'] = $id;
        echo json_encode($response);
    } else {
        showJson(2, "Cannot login\nCheck your Credentials");
    }
}
     $data = getUserData($_POST['login_mail'], $db);
     if ($data !== false) {
         // create the password
         $typedPassword = hash('sha512', $_POST['login_password'] . $data['user_salt']);
         if ($typedPassword == $data['user_hash']) {
             // Fill Session
             $_SESSION['user_id'] = $data['user_id'];
             $_SESSION['user_mail'] = $_POST['login_mail'];
             $_SESSION['user_role'] = $data['user_role'];
             $_SESSION['user_status'] = $data['user_status'];
             if (empty($data['contact_name']) || empty($data['contact_street']) || empty($data['contact_zip']) || empty($data['contact_city'])) {
                 $_SESSION['has_contact'] = false;
             } else {
                 $_SESSION['has_contact'] = true;
             }
             updateLastLogin($_SESSION['user_id'], $db);
             header('Location:/dashboard');
         } else {
             $responseLog[] = 'Das Passwort ist falsch!';
         }
     } else {
         $responseLog[] = 'Dieser Benutzer existiert nicht!';
     }
 }
 if (empty($_POST['login_mail'])) {
     $responseLog[] = 'Bitte geben Sie Ihren Benutzernamen ein!';
 }
 if (empty($_POST['login_password'])) {
     $responseLog[] = 'Bitte geben Sie Ihr Passwort ein!';
 }
 break;
Exemple #4
0
/** 
 * @author Simone Romano
 */
function checkUserPassword($email, $password)
{
    $conn = getConn();
    $sql = "SELECT * from utente where email='{$email}'";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        //user in db
        session_start();
        if (!isset($_SESSION['email'])) {
            while ($row = mysqli_fetch_assoc($result)) {
                $confirmed = $row['confirmed'];
                if ($confirmed == 0) {
                    return -3;
                }
                $passwordInDb = $row['password'];
                $test = md5($password);
                if (md5($password) == $passwordInDb) {
                    $_SESSION['email'] = $email;
                    $_SESSION['name'] = $row["name"];
                    $_SESSION['surname'] = $row["surname"];
                    $_SESSION['sex'] = $row["sex"];
                    $_SESSION['picture'] = $row["imPath"];
                    $_SESSION['birthday'] = $row["birthday"];
                    $_SESSION['registrationDate'] = $row["registrationDate"];
                    $_SESSION['lastLogin'] = $row["lastLogin"];
                    $_SESSION['webPage'] = $row["webPage"];
                    $now = (new \DateTime())->format('Y-m-d H:i:s');
                    updateLastLogin($email, $now);
                } else {
                    mysqli_close($conn);
                    return -1;
                }
            }
        }
    } else {
        //insert user in db
        mysqli_close($conn);
        return -2;
    }
    mysqli_close($conn);
    return 1;
}