Looking for a some good options to send users reset password emails

后端 未结 2 344
面向向阳花
面向向阳花 2020-12-16 07:57

I want to send emails to users when the forget their passwords that prompt them to reset their passwords. I know this is debatable and was looking for a few good options/sug

2条回答
  •  不知归路
    2020-12-16 08:35

    Here's what I do:

    I have reset_password table. When someone asks for a reset, they usually click a link on your site that says "forgot password" where they enter their email they registered with and your system sends a link. Of course you begin with finding out if the user is registered at all. by selecting from users where email = $_POST['email']. If they exist, make a randomly generated token, like

    $token = md5($_POST['email'].time());
    

    But as Buh Buh expressed in the comment below, you may want to use something a little less obvious to generate your token. crypt() can accept a salt pattern if you like.

    Insert the request (email and token) in the reset_password table, then you send them a link like

    http://www.domain.com/resetpassword.php?token=
    

    Then in that file you take the $_GET['token'] and cross reference it with the reset_password table. If the token is valid, you present them with a form that asks for their new password. Upon submit, select the user with the email address related to that token and update the user table.

提交回复
热议问题