Blog | G5 Cyber Security

Password Reset: Email Validation & Security

TL;DR

Asking for a password *after* email validation is bad cyber security practice. It confirms to attackers that the email address exists, making it easier to target your account. Instead, focus on robust password reset flows with strong verification methods.

Why Asking For A Password After Email Validation Is Risky

When you ask for a password immediately after someone enters their email address, you’re essentially telling anyone who tries that the email is registered to an account. This opens up several attack vectors:

How To Fix It: A Secure Password Reset Flow

Here’s how to implement a much safer password reset process:

1. Initial Email Request

  1. Only ask for the email address initially. Do not prompt for any password information at this stage.
  2. Generate a unique, time-limited token. This token should be cryptographically secure (e.g., using UUIDs or similar).
  3. Store the token securely in your database associated with the user’s email address. Include an expiry timestamp.
  4. Send an email containing a link with the token. The link should point to a password reset page on your website. Do not include the token directly in the email body; use it as part of the URL. Example:
    https://yourwebsite.com/reset-password?token=abcdef1234567890

2. Password Reset Page

  1. Validate the token: When a user clicks the link, verify that:
    • The token exists in your database.
    • The token hasn’t expired.
    • The token is associated with the correct email address.
  2. Present a form to set a new password. This should include standard password strength requirements (length, complexity).
  3. Hash and salt the new password securely before storing it in your database. Never store passwords in plain text! Use a strong hashing algorithm like bcrypt or Argon2.
    # Example using Python with bcrypt
    import bcrypt
    password = b'your_new_password'
    hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
    print(hashed_password)
  4. Invalidate the token after successful password reset. This prevents reuse of the same token.

3. Additional Security Measures

Exit mobile version