Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4081838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:06:45+00:00 2026-05-20T18:06:45+00:00

I have a simple question. What is the best way to do a password

  • 0

I have a simple question. What is the best way to do a password recovery for a user?

I want the user to be able to click a link like “forget your password?” When clicked, the user will receive an email with a new password.

I think sending the hash is a bad option, then I must generate a random password, convert to a hash + random salt, replace it in the database and send the new random password by email. Is this the best way, or is there another? Simpler is better.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:06:46+00:00Added an answer on May 20, 2026 at 6:06 pm

    The safest way is to email the person a link to a page that allows them to create a new password. Passwords should only ever be stored as salted hashes. Subverting this process would require that a person’s email be compromised — in which case they’ve probably got worse problems than a compromised password to your webapp.


    Files and tables:

    I imagine that your database contains a table called “users”, with a column called “userid” which serves as its primary key.

    1. Create a new table in your tabase called password_reset with three columns: userid, which is a foreign key pointing to the table users; code, which will contain a unique, random number; and timestamp, which will contain the date that a request is made.

    2. Create a page for password resets, like password_reset_request.php. Ask for a username or email.

    3. Create a page for setting a new password, like set_new_password.php.

    Logic:

    1. If the username or email supplied to password_reset_request.php is valid, insert a row in the password_reset table corresponding to the request. Imagine that user Fel has placed a password reset request. Fel‘s internal userid might be 564979. The row in password_reset would be something along these lines: 564979, 54c4a2767c2f485185ab72cdcf03ab59, 2011-01-01 12:00:00.

    2. Send an email to the user’s email address containing an url looking like this: http://your.url/set_new_password.php?userid=564979&code=54c4a2767c2f485185ab72cdcf03ab59.

    3. When set_new_password.php gets a hit, it should check for the presence of the userid and code properties in the URL. Not there? Abort.

    4. Sanitize the userid and code properties if they’re there. This is important.

    5. Run an SQL command like this: SELECT * FROM password_reset pr WHERE pr.userid = $userid AND pr.code = $code AND TIMESTAMPDIFF(DAY, CURTIME(), pr.timestamp) < 1.

    6. If you receive no results, Abort.

    7. If you receive a result, allow the user to enter a new password.

    8. After validating the password as you normally would upon registration, use an SQL UPDATE statement to change the user’s password.

    9. Use SQL to delete any requests for the user from the password_reset table: DELETE * FROM password_reset WHERE userid = $userid.

    You’re done!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relativly simple question. What would be the best way to recreate
Simple question on best practice. Say I have: public class Product { public string
I have a simple question. Is there a way ( using reflections I suppose
I have a simple ruby question. I have an array of strings. I'd like
Simple question: If I have a string and I want to add to it
Simple question, hopefully an easy way and just want to verify I'm doing it
I have a very simple question. Is there any way to relate database errors
I have a simple collections question. I have a Set<String> object. I want an
Simple question, what's the best way to exclude words such as 'a' and 'the'
What is the best way to convert user input to UTF-8? I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.