生成安全代码的算法

发布于 2025-01-06 00:08:49 字数 388 浏览 0 评论 0原文

我需要知道是否有某种已知的算法来生成安全代码。场景是这样的:

我有一个 Web 应用程序,其中用户有一个密码和一个电子邮件,需要在应用程序中进行识别和验证。 如果用户忘记了密码,我需要启用通过以下方式恢复密码的功能:

这应该

  1. 与一个窗口一起使用,用户在其中输入他的电子邮件,然后单击 名为“忘记密码”的按钮(或类似的内容)
  2. 此按钮应向用户的电子邮件发送安全代码
  3. 然后应用程序将用户重定向到新页面,用户必须在其中输入 收件箱中收到安全代码
  4. 如果用户输入的安全代码有效,那么他将被重定向到可以输入新密码的页面。

我正在寻找的是某种已知的方法来生成安全代码(步骤 2)并验证此安全代码(步骤 4)

提前致谢

I need to know if there is some kind of known algorithm to generate security codes. This is the scenario:

I have a web application, where the users has a password and an email to be identified and authenticated into the application.
In case the user forgots his password, I was required to enable the funcionality of recovering it in the following way:

This should wor

  1. k with a window, where the user enter his email, and click on a
    button called "forgot password" (or something similar)
  2. This button should send a security code to the users email
  3. Then the application redirects the user to a new page, where the user must enter the
    security code received in his inbox
  4. If the security code entered by the user is valid, then he is redirected to a page where he can introduce a new password.

What I'm looking for, is for some kind of known ways to generate the security code (step 2) and to validate this security code (step 4)

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

记忆里有你的影子 2025-01-13 00:08:49
  1. 生成随机代码。
  2. 将其存储在您的数据库中。
  3. 在新页面上,将其加载回来并与用户输入进行比较。

这里不需要加密。

  1. Generate a random code.
  2. Store it in your database.
  3. On the new page, load it back and compare to user input.

There's no cryptography required here.

人疚 2025-01-13 00:08:49
  • 创建一个包含 20 个字符左右的唯一代码。 (数字、字母和特殊字符)
  • 将其保存在数据库中,并带有时间戳,
  • 将代码发送给用户。
  • 确保代码仅在 24 小时内有效
  • Create an unique code with something like 20 characters. (numeric, alpha and special characters )
  • Save it in a database with a timestamp
  • send the code to the user.
  • make sure the code only works for something like 24 hours
海未深 2025-01-13 00:08:49

您可以使用消息身份验证代码来实现此目的。

You can use Message authentication code for this purpose.

梦太阳 2025-01-13 00:08:49

正如前面的答案所述,您可以生成一个随机数和一个 32 位字符串密钥,存储在数据库中并将其传递到页面。要求用户输入数字,但 32 位应作为隐藏值放置在页面中。用户输入号码并提交后,这两个值都将到达后端,您可以验证这一点。如果匹配则允许或生成一个新的并再次呈现页面。这可以避免猜测以及暴力破解。

As told in the previous answer you can generate a random number and also a 32 bit string key, store in the database and pass it to the page. Ask the user to enter the number, but the 32 bit should be placed as a hidden value in the page. Once the user enters the number and submits both the values will come to the backend and you can verify that. If matches then allow or generate a new one and render the page again. This avoids guessing as well as brute forcing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文