- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我的用户忘记密码时,他们会被发送到如下所示的页面。我在 JavaScript 中生成一个随 secret 码,对其进行加密,然后将纯文本和 md5 哈希值发送到 Servlet。然后,Servlet 将密码通过电子邮件发送给用户,并将 md5 哈希值存储在我的数据库中。这个过程在大多数情况下都运行良好。但由于某种原因,经常会生成错误,生成的密码长度为 0。
我单独测试了我的 JavaScript 代码,并让它生成了数百个密码。没有一个长度为 0。那么这个错误从何而来?
这是 HTML 表单:
//This method returns a randomly generated mathy password.
function randomPassword(theForm) {
first = ["Euler", "Erdos", "Newton", "Eucl1d", "Gauss", "H1lb3rt", "Cantor", "Bernoulli", "PascaL"];
second = ["Const", "Number", "Theorem", "Prime", "Ratio", "Lemma", "Postulate", "Method", "Algorithm"];
symbol = ["!","@","#","$","%","^","&","*","_","+","-","?"];
a = Math.floor(Math.random() * first.length);
b = Math.floor(Math.random() * second.length);
n = Math.floor(Math.random() * 10);
style = Math.floor(Math.random() * 3); //0,1, or 2
if(style==0) password = first[a] + n + second[b];
else if(style==1) password = first[a] + second[b] + n;
else password = first[a] + second[b] + symbol[n];
theForm['newPass'].value = password;
theForm['passwordLog'].value = "style="+style + " a=" + a + ", b=" + b+ ", n=" + n;
hashField = theForm['passHash'];
hashField.value = hex_md5(password);
theForm.submit();
}
<body>
<h2>You can reset your password below.</h2>
<form action="ResetPassword" method="post" >
Enter your e-mail address:
<input type="text" name="eMail" id="eMail" size="20"/> <br />
<input type="button" value="Reset Password" onclick="randomPassword(this.form);" />
<input type="hidden" id="passHash" name="passHash" />
<input type="hidden" id="newPass" name="newPass" />
<input type="hidden" id="passwordLog" name="passwordLog" />
</form><br/>
<strong>Attention Coaches: If you are having trouble logging into this system,
please contact the scorekeeper: llaspina@bethpage.ws </strong>
</body>
这是接收从上述文件发送的表单数据的 Servlet:
@WebServlet(name = "ResetPasswordServlet", urlPatterns = {"/ResetPassword"})
public class ResetPasswordServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
ConnectionPool pool = ConnectionPool.getInstance();
java.sql.Connection con = pool.getConnection();
String emailAddress = request.getParameter("eMail");
String newPass = request.getParameter("newPass");
String passHash = request.getParameter("passHash");
String log = request.getParameter("passwordLog");
try {
Coach coach = null;
ArrayList<Coach> coachList = MathTeamDAO.getAllCoaches(con);
for(Coach c : coachList) {
if(c.email.equals(emailAddress) ) {
coach = c;
break;
}
}
out.println("<html><head><title>Scorekeeper Reset Password Servlet</title></head>");
out.println("<body>");
out.println("<h1>Reset Password Servlet</h1>");
if(coach==null) {
out.println("Your email address was not found in our database.<br/>" +
"Please contact the scorekeeper or the secretary to gain access to the sytem.");
}
else {
if(newPass == null || newPass.length()<3) {
out.print("An error occurred while generating a random password. The randomly generated password came back as ");
out.print(newPass);
out.println(" Please try to <a href=\"resetPassword.html\">reset your password</a> again.");
String errorMsg = "An error was encountered while attempting a password reset. ";
if(newPass==null)
errorMsg += "null newPass generated.";
else
errorMsg += " The newPass had length " + newPass.length() + " and =" + newPass;
if(log!=null)
errorMsg += ("\n" + log);
if(UtilityServlet.emailAnError(coach,errorMsg, this.getServletName() + " at " + this.getServletName()))
out.println("<br/>The scorekeeper was just informed of this error through email, so you do not need to report it.");
}
else {
out.println("<h3>Check your email for your new password and directions for signing into the scorekeeper system.</h3>");
out.print("Sending new password to " + coach.email + "<br/>");
ChangePasswordServlet.changePassword(con, coach.schoolID, passHash);
School herSchool = MathTeamDAO.getSchoolByCoach(con, coach);
String emailServerMessage = ChangePasswordServlet.sendPasswordEmail(coach, herSchool.shortName, newPass);
if(herSchool!=null) {
out.print("<br/>The username for " + herSchool.fullName);
out.print(" is <strong>");
out.print(herSchool.username);
out.println("</strong><br/>");
}
out.print(emailServerMessage);
}
out.flush();
}
out.println("<br/>Return to <a href=\"login.jsp\" >login page.</a>");
out.println("</body></html>");
}
catch(java.sql.SQLException utoh) { }
finally {
pool.freeConnection(con);
out.close();
}
}
请注意,如果密码为空或太短,我会收到向自己发送的错误消息。这种情况经常发生,而且它们的长度总是 0。为什么?
最佳答案
此行中间有注释:
else //if(style==2) password = first[a] + second[b] + symbol[n];
在大约三分之一的情况下,您将获得未定义的密码...
关于java - 创建随 secret 码会生成长度为 0 : Blame JavaScript or Java Servlet? 的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13694745/
我正在尝试在我的 minikube 上启动并运行 keycloak。 我正在安装keycloak helm upgrade -i -f kubernetes/keycloak/values.yaml
我将我的数据库密码存储到AWS密钥管理器的Secret Value字段中。如果我使用以下代码,如何检索密码值?。在密钥管理器中定义的密钥:密钥在密钥管理器中定义的值:DBPwd。当我写入日志文件时,上
I am storing my database password into the Secret value field in the aws secret manager. How do I
我正在尝试在 AWS CDK 上组合一个相对简单的堆栈,其中涉及来自 aws-ecs-patterns 的 ApplicationLoadBalancedFargateService。 我的问题涉及
今天我在悠闲地阅读时偶然发现了 Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryp
不是一个真正的编程问题,但很想知道 Kubernetes 或 Minikube 如何管理 secret 并在多个节点/pod 上使用它? 假设我创建了一个 secret 来使用 kubectl 提取图
我需要从 AWS dynamoDB 和第三方 https 服务中获取元素并将这些结果合并到 AWS appSyn 中并将结果作为 graphQL 响应发回 我正在使用的第三方服务需要客户端证书。我没有
我收到一个错误: gpg: no default secret key: No secret key gpg: [stdin]: clearsign failed: No secret key GPG
我正在尝试为 kubernetes 集群设置私有(private) docker 镜像注册表。我正在关注 link $ cat ~/.docker/config.json | base64 ew
当我开发一个API服务器时,我需要给API服务器一些账户信息,这些信息不应该给任何人看。K8s对这种情况推荐secret,所以我用了。 但我想知道这个 secret 是否真的是 secret 。 se
在大多数有关在 Kubernetes 中使用 secret 的示例中,您都可以找到类似的示例: apiVersion: v1 kind: Secret metadata: name: mysecr
我正在与 terraform 合作,在 azure 中启动不同的资源。其中一些资源包含敏感数据,我希望将其安全地存储在 aws Secret Manager 中。这在 Terraform 中是可行的过
我有带有有效 key 的 Azure 应用程序注册。 我正在尝试使用 v1.0 获取 token ,如下所示(clientId 是上述应用程序注册的 ID) $body = @{ grant_
本文讨论如何安装 secret 卷。 https://learn.microsoft.com/en-us/azure/container-instances/container-instances-v
我正在使用 kubernetes 将 Rails 应用程序部署到谷歌容器引擎。 遵循 kubernetes secret 文档:http://kubernetes.io/v1.1/docs/user-
我正在与 terraform 合作,在 azure 中启动不同的资源。其中一些资源包含敏感数据,我希望将其安全地存储在 aws Secret Manager 中。这在 Terraform 中是可行的过
我有带有有效 key 的 Azure 应用程序注册。 我正在尝试使用 v1.0 获取 token ,如下所示(clientId 是上述应用程序注册的 ID) $body = @{ grant_
本文讨论如何安装 secret 卷。 https://learn.microsoft.com/en-us/azure/container-instances/container-instances-v
我有一个 python 脚本,它在 AWS 中创建一些访问 key 并将它们存储在 secret 管理器中。 但是,当我存储 key 时,我收到一条错误消息: The secret value can
我在 Secrets Manager 控制台上创建了一个 key 。然后我尝试使用 Go 代码 quickstart guide喜欢 ctx := context.Background() clien
我是一名优秀的程序员,十分优秀!