简体   繁体   English

创建用于验证的user_session表。

[英]Creating a user_session table for authentication.

I am developing an android application which uses php webservices. 我正在开发一个使用php webservices的android应用程序。 I have been having issues with handling sessions between the server-side and the client-side, so I decided to do a different approach. 我在处理服务器端和客户端之间的会话时遇到了问题,因此我决定采用其他方法。 I am planning on create a user_session table which will contain the session_id, user_id, session_token and expiry_date. 我计划创建一个user_session表,其中将包含session_id,user_id,session_token和expiry_date。

The session_token will be generated using some fields from the users while the expiry_date is date for when the session_token will be re-generated or changed to null. session_token将使用用户的某些字段生成,而expiry_date是将session-token重新生成或更改为null的日期。 This will mean that the user will need to log in again on the android. 这意味着用户将需要再次登录android。

A scenario: 1. The user enters correct credentials 2. The web-service generate a session_token for the user, stores it in the user_session table and sends the value to the client-side. 一个场景:1.用户输入正确的凭据2. Web服务为该用户生成一个session_token,将其存储在user_session表中,并将该值发送到客户端。 3. For every request from the android application, the web-service will verify if the session_token on the client-side corresponds to the session_token in the table. 3.对于来自android应用程序的每个请求,Web服务都会验证客户端的session_token是否对应于表中的session_token。

My questions: 1. Can you help me in creating the session_token and the expiry_date as I do not know how to generate a unique value in php using other fields. 我的问题:1.您能帮助我创建session_token和expiry_date吗,因为我不知道如何使用其他字段在php中生成唯一值。 2. Is it worth it in terms of security? 2.就安全性而言值得吗?

Thank you for your help 谢谢您的帮助

You can use hasing: 您可以使用hasing:

$token = sha1($ssid.$something);

$ssid = session_id();

That $token variable it's your token .. insert it in database, and create conditions. 该$ token变量是您的令牌..将其插入数据库,并创建条件。 It's unique, it's based on session id and other "think" You can use email address or other field... but be carefull, if the user change that field, you need to generate again the token 它是唯一的,基于会话ID和其他“思考”,您可以使用电子邮件地址或其他字段...但是请注意,如果用户更改了该字段,则需要再次生成令牌

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM