dongshi8359 2010-01-08 21:54
浏览 88

PHP pam_auth和cookies

Long story short, I'm developing an in-house report engine. It is entirely web based (utilising PHP and various AJAX techniques) and interprets data stored in a MySQL database by our production software. It runs on an Ubuntu 8.04 server, and all employees have a linux user account on that machine. I set up a login system using pam_auth that forces a user to log in with their linux user account and determines whether or not they belong to the appropriate group to access particular reports.

That part works great, my problem here is adding a "remember me" function using cookies. I would like for users to have a 30-day cookie just to save them some time and aggravation having to log in every time their session expires. I wrote the "remember me" portion of the code and it stores the cookie just fine. I'm storing only their user name and a md5 hash of their password. The problem here comes when it's time to re-authenticate them. Normally I'd simply do this by comparing the stored username with a password hash of that user from the database. What complicates things is that I don't have direct access to the usernames and password hashes. They are all stored in /etc/passwd and /etc/shadow and logins are handled by the PAM module. pam_auth expects a plain text username and plain text password.

It seems like my only alternatives are to either store the password as plain text, or with a reversible encryption, but I don't particularly like either of those ideas.

Are there any better solutions here?

  • 写回答

1条回答 默认 最新

  • dongyunwei8596 2010-01-08 22:31
    关注

    Another option you could use is PHP's built in session management. Then the only cookie that needs to be set on the user's computer is the session ID which PHP will do for you automatically.

    You can set the PHP session length to at least 30 days by changing these two ini settings: 'session.cookie_lifetime' and 'session.gc_maxlifetime'. Then once a user has logged in you can store their username and when they logged in in the $_SESSION super global array after calling session_start(). When a user returns you can check the values in the $_SESSION array to see if they had logged in and whether or not it was fewer than 30 days ago.

    Now if you still need the PAM authentication at this point for other reasons you would have to store their password in the session variable either as clear text or reversibly encrypted. While that is non-ideal it is more secure than as a cookie in the user's browser. For more information look at the PHP Session - Manual.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?