Skip to content

Instantly share code, notes, and snippets.

@flackend
Created February 5, 2020 02:14
Show Gist options
  • Select an option

  • Save flackend/14a8b60043a89ee8651a5d766196e6d6 to your computer and use it in GitHub Desktop.

Select an option

Save flackend/14a8b60043a89ee8651a5d766196e6d6 to your computer and use it in GitHub Desktop.

Revisions

  1. flackend created this gist Feb 5, 2020.
    20 changes: 20 additions & 0 deletions auth.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?php

    try {
    $user = get_user_from_database($emailFromLoginForm); // pseudo

    if ($user->password === md5($plainTextPasswordFromLoginForm)) {
    // We've identified that the password in the database is a md5 hash, so
    // we'll salt and hash the plain-text password and save it
    $saltedPassword = password_hash($plainTextPasswordFromLoginForm, PASSWORD_DEFAULT);
    $user->password = $saltedPassword; // pseudo
    $user->save(); // pseudo
    }
    if (!password_verify($password, $user->password)) {
    throw new LoginException('Invalid password.');
    }
    return true;
    } catch (LoginException $e) {
    log('debug', $e->getMessage());
    return false;
    }