Skip to content

Instantly share code, notes, and snippets.

@bradynpoulsen
Last active January 22, 2017 12:10
Show Gist options
  • Select an option

  • Save bradynpoulsen/4a418559c6543de984a7e5e17cd7d8c4 to your computer and use it in GitHub Desktop.

Select an option

Save bradynpoulsen/4a418559c6543de984a7e5e17cd7d8c4 to your computer and use it in GitHub Desktop.

Revisions

  1. bradynpoulsen revised this gist Jan 22, 2017. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. bradynpoulsen created this gist Jan 22, 2017.
    20 changes: 20 additions & 0 deletions login.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?php

    $providedEmail = $_SERVER['PHP_AUTH_USER'];
    $providedPassword = $_SERVER['PHP_AUTH_PW'];

    $user = User::find_by_email($providedEmail);
    if ($user) {
    if (password_verify($providedPassword, $user->password_digest)) {
    session_start();
    $_SESSION['user_id'] = $user->id;

    header('HTTP/1.1 200 Ok');
    header('Location: https://example.com/my-account');
    echo 'You have successfully logged in!';
    exit();
    }
    }

    header('HTTP/1.1 403 Forbidden');
    echo 'You provided an invalid email/password';
    6 changes: 6 additions & 0 deletions signup.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <?php

    $user = new User;
    $user->email = 'foo@example.com';
    $user->password_digest = password_hash('mypassword', PASSWORD_DEFAULT);
    $user->save();