开发者

User Authentication and Sessions with Javascript

开发者 https://www.devze.com 2023-03-12 07:53 出处:网络
I am writing an application using Sencha Touch that will require a login to the server.I need a way of keeping track of the s开发者_JAVA百科ession, but I\'m not sure what the best way of doing this is

I am writing an application using Sencha Touch that will require a login to the server. I need a way of keeping track of the s开发者_JAVA百科ession, but I'm not sure what the best way of doing this is. It seems that in HTML5 there is 'sessionStorage' which can be used for this.

From what I understand I need to do the following:

1. Send username/password to server

2. If combo is correct, server sends some session ID variable to phone

3. Phone saves sessionID in sessionStorage

4. Every time the phone communicates with the server it sends sessionID with message

5. Server checks a message for correct sessionID (and possibly checks IP address too)

6. When user logs out of app, sessionID is wiped from phone and server

Can you please let me know if this is the correct route to take?


I usually have handled everything on the client side stored in a JS object. Not sure if it's a best practice or not, but it has worked for me. If I'm storing a password I encrypt it and only match it with the hash to see if it is valid. For session time outs you can set up a timer and for every Ajax request check whether the "session" is still valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消