如何通过在java中向用户发送邮件来创建密码重置链接的链接

时间:2014-11-13 06:41:09

标签: java

 String messageValue[] = {userNameFull, programName, url, url, newPass, programSupportEmail, programSupportEmail, programSupportPhone, signature, programWebsite};

            //String subject = MessageUtil.getMessage("mail.ResetPasswordSubject", locale);
            //String message = MessageUtil.getDynamicMessage("mail.UserMailForgotPassword", messageValue, locale);;
            //mail.ResetPasswordSubject = Password Reset Request
            String subject = "Password Reset Request";
            String message = "Dear {0}"
                    + ",<br/>"
                    + "Greetings from the {1} Team."
                    + "<br/><br/>"
                    + "Your password has been reset."
                    + "<br/><br/>"
                    + "To access your account, "
                    + "please click on the following link:<br/>"
                    + "<a href={2}>{3}</a>"
                    + "<br/>"
                    + "or copy the link and paste it in your browser&#39s address bar."
                    + "<br/><br/>"
                    + "Your temporarily reset password will expire in 7 days "
                    + "and you will be asked to change it on your first login."
                    + "<br/>Login to your account using the following details:"
                    //+ "<br/><br/>Password:{4}"
                    //+ "<br/><br/>Password:"+newPass+""

在这里我必须输入重置密码的链接代替这个“

密码:”+ newPass +“”请帮帮我

1 个答案:

答案 0 :(得分:1)

按照以下步骤,从安全角度避免暴力攻击。

  1. 创建32个字母数字字符串作为sessionid,有效期至7天(在您的情况下)
  2. 创建代码8/12 char构造代码
  3. 将重置链接与查询参数中的sessionid和电子邮件中的conf代码放在一起。
  4. 当用户点击链接时,让他在ui上插入conf代码。
  5. 验证会话ID和conf代码
  6. 全部有效,然后向他显示他的用户名并要求输入新密码并确认密码。