密码保护,同时跟踪谁是谁
我维护一个农贸市场网站。该网站的一部分包括一个数据库,其中包含所有不同农民以及他们本周收获的作物。
目前,我有一组管理页面,由于我没有告诉任何人它们在哪里,所以这些页面对公众隐藏。通过管理页面,我根据需要编辑数据。随着越来越多的农民参与进来,更新他们的数据变得很痛苦,我想将其设置为每个农民都可以注册,使用自己的密码登录并编辑他们本周在市场上的产品,而无需我参与。
我见过很多关于密码保护页面的脚本。我所看到的那些已经设置为一旦用户登录,他们就可以查看所有内容,并且似乎没有一种简单的方法来跟踪登录者。
如何在跟踪的同时建立密码保护谁是谁,以便我可以即时构建自定义管理页面?有什么提示或最佳实践需要牢记吗?
谢谢,
布兰丹 PS我一直在使用PHP和SQLite
I maintain a farmer market site. Part of the site includes a database with all of the different farmers and what they are harvesting this week.
Currently I have one set of admin pages that are hidden from the public by the fact that I have not told anyone where they are at. With the admin pages I edit the data as needed. As more farmers get involved, it is getting to be a pain updating their data and I want to set it up so each farmer can signup, log on with their own password and edit what they have at market this week without me getting involved.
I have seen plenty of scrips for password protecting a page. The ones that I have seen have been set up so that once a user is signed in they can view everything and there does not appear to be an easy way to keep track of who signed in.
How do I build password protection, while keeping track of who is who, so that I can build the custom admin pages on the fly? Any tips or best practices to keep in mind?
Thanks,
Brandan
P.S. I have been using PHP and SQLite
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按照您在网上找到的这些脚本进行操作。
归结为:
md5()
和 i也会使用盐键(所以类似于 MD5($password.$salt)) - SALT 可以是用户注册时的时间戳、随机的字母/数字字符串(我推荐) - 并将其保存在数据库中。$_SESSION['loggedin'] = true;
然后在每个受保护页面的顶部,您可以执行一些操作,如下例所示time()
code>) 或 datetime (date("Ymd H:i:s")
) 到标记为 last_logged_in 的列下的数据库我知道这不是一堆代码,但它构成了一个基本指南让你开始
以上示例
Follow these scripts that you find online.
All it boils down to is:
md5()
and i'd use a salt key too (so something like MD5($password.$salt)) - the SALT can be a timestamp of when the user signed up, a random string of letters/numbers (which I'd recommend) - and save this as well in the database.$_SESSION['loggedin'] = true;
then at the top of each protected page you can do some like in the example belowtime()
) or datetime (date("Y-m-d H:i:s")
) to the database under a column labelled last_logged_inI know this isn't a load of code but it forms a basic guide to get you started
Example For Above
确保每个用户都有唯一的登录名(最好是电子邮件)和密码。然后创建一个包含 2 个用户名和密码输入字段的表单,并在回发后将值与数据库进行匹配。如果数据匹配,则将 user_id (或更多用户数据)存储在会话中。
Make sure each user has a unique log-in (preferably e-mail) and password. Then create a form with 2 input fields for username and password, and after postback, match the values against the database. If the data is a match, store the user_id (or more user data) in a session.
为了找出谁是谁,我会使用 session($_SESSION 变量)
制作一些简单的登录页面,设置一些 id`s 或使用电子邮件作为登录,如果你愿意,你也可以制作一些注册页面。
使用随机字符串作为用户的密码,将其发送给他们并告诉他们在首次登录时更改密码。
不要将密码存储在数据库中。仅使用密码哈希(例如 sha512)。如果您想提高安全性,请使用一些服务器盐或用户盐。
每次登录时,将用户输入的密码哈希值与数据库中存储的密码进行比较。
注意 SQL 注入漏洞,我建议使用 PDO 并插入变量作为参数。
For finding out who is who, I would use sessions($_SESSION variable)
Make some simple login page, set some id`s or use emails as login, if you want you can make some registration page too.
Use random strings as passwords for users, send it to them and tell them to change password on first login.
DO NOT STORE PASSWORD IN DB. Use only password hashes(sha512 for example). If you want to improve security use some server salt or user salt.
On every login compare hash of password that user put in with password stored in db.
Watch out for SQL injection vulnerabilities, i would advise to use PDO and insert variables as parameters.
您可以使用 Basic HTTP-Auth 或基于 < a href="http://www.php.net/manual/en/book.session.php" rel="nofollow">会话。在这两种情况下(分别是唯一名称和会话 ID),跟踪用户都非常容易。
You can use Basic HTTP-Auth or you build your own based on Sessions. Tracking the user is very easy in both cases (Unique name and Session id respectively).