如何创建登录模块

发布于 2024-09-28 20:46:40 字数 127 浏览 1 评论 0 原文

我必须创建一个登录模块(问题不是特定于语言的),但我不确定如何验证用户。我将在哪里以及如何存储密码。我是否必须加密和解密我的密码?如果是,最好的建议方法是什么?总的来说,我需要知道开发登录模块需要注意什么,用户可以安全地登录以访问我的网站。

i have to create a login module (The question is not language specific) but i am not sure how will i validate the user. Where and how will i store the passwords. Will i have to encrypt and decrypt my passwords and if yes what are the best suggested way to do them. Overall i need to know what all things i need to take care of for developing a login module where a user can login securely to access my site.

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

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

发布评论

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

评论(2

追星践月 2024-10-05 20:46:40

您不需要解密密码来验证它们,只有一种加密方法可以很好地实现这一点。这个想法是,当用户输入密码时,您以相同的方式对其进行加密(使用相同的算法和“盐”),然后与存储在数据库中的加密密码进行比较。如果它们相等,则很有可能是相同的原始密码。因此,您可以防止任何人(管理员或任何攻击者)知道用户在您的网站上使用的原始密码。

至于其余的,非常简单,您的数据库中有一个表,其中包含用户登录名、加密密码以及可能的一些个人资料信息(全名等)。

我通常使用以下函数来哈希用户密码:

$password_hash = sha1(MY_SALT_1 . $login_name . MY_SALT_2 .
    $password . MY_SALT_3);

其中 MY_SALT_* 是任意预定义的字符串,可以是例如“黑暗”、“侧面”、“月亮”(或者实际上越不相关 - 越好)。

You don't need to decrypt your passwords in order to validate them, just one way encryption works fine for this. The idea is that when a user enters a password, you encrypt it the same way (using the same algorithm and "salt") and then compare with the encrypted one stored in your database. If they are equal, with a great probability it means it's the same original password. Thus you prevent anyone - the adminstrator or any attacker - from knowing the original passwords users use on your web site.

As for the rest, it's very simple, you have a table in your database which contains user logins, encrypted passwords, and possibly some profile information as well (full name, etc).

I usually use the following function to hash user passwords:

$password_hash = sha1(MY_SALT_1 . $login_name . MY_SALT_2 .
    $password . MY_SALT_3);

where MY_SALT_* are arbitrary predefined strings, could be e.g. 'the dark', 'side of', 'the moon' (or actually the less related - the better).

还在原地等你 2024-10-05 20:46:40

是的。当然你需要加密用户密码。因为大多数用户几乎所有网站都使用相同的密码。那时他们不想向管理员显示密码。另一个原因是大多数时候网站数据库可能是不仅由管理员访问。组织中的其他一些技术人员也可以访问。因此最好对密码进行加密。SHA1 是最好的加密方式。
我将在哪里以及如何存储密码。
我不确定你的意思。每个人都使用数据库,例如 phpmyadmin。

Yes.Sure you need to encrypt users passwords.Because most of the users using the same password almost all sites.At that time they are not want to show the passwords to admin.And another reason is most of the time the site DB may be accessed not only by admin.Some other technical persons in the organization.So it is better to encrypt the password.SHA1 is the best way to make the encryption.
Where and how will i store the passwords.
I am not sure what you mean by this.Every one use the database for it like phpmyadmin.

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