Cordova应用程序与自动登录功能 [英] Cordova app with autologin feature

查看:715
本文介绍了Cordova应用程序与自动登录功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式有一个登入画面,让使用者可以输入名称和密码登入。
此外,我有一个复选框记住我。
如果我登录并玩耍,一切正常。但是如果我重新启动应用程序,我意识到我的应用程序有一个新的会话ID。



这是一个问题。不知怎的,如果用户通过上次登录选择了记住我复选框,我需要通过应用程序启动登录。



我意识到有一个基于令牌的解决方案。您的后端会创建一个令牌,并将其与会话ID进行映射。然后它发送令牌到客户端(应用程序),它保存在本地存储。

解决方案

这是我的解决方案:


  1. 我使用https,通过此插件检查证书: https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin


  2. 我的应用程式使用这个外挂程式加密: https://github.com/tkyaji/cordova-plugin-crypt-file p>


  3. 用户通过ajax(发送:username,password,device-uuid)发送登录请求,并从服务器接收令牌。


  4. 我使用该令牌在我的应用程序中做相同的压缩,并使用此插件将其保存在本地sqlite数据库中: https://www.npmjs.com/package/cordova-sqlite-storage


  5. 在每个ajax请求中,我发送解密的令牌和device-uuid。


  6. 我会不时更改凭证。



My app has a login screen, where user can input name and password to login. In addition I have a checkbox called "Remember me". If I login and play around, everything works fine. But if I restart the app, I realized that my app has got a new session id.

Thats a problem. Somehow I need to login in the backend by app start if user selected the "Remember me" checkbox by last login.

I realized that there is a token-based solution. Your backend creates a token and maps it with the session id. Than it sends the token to the client (app) which persists it in localstorage. How do you do it?

解决方案

That is my solution:

  1. I use https, checking the certificate by this plugin: https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin

  2. My app is crypted with this plugin: https://github.com/tkyaji/cordova-plugin-crypt-file

  3. The user is sending a login request via ajax (sending: username, password, device-uuid) and receives a token from the server.

  4. I do same cryption in my app with the token and save it in a local sqlite database using this plugin: https://www.npmjs.com/package/cordova-sqlite-storage. The reason for the cryption is, that it is possible to copy the database.

  5. On every ajax-request I send the decrypted token and the device-uuid.

  6. From time to time I change the token.

这篇关于Cordova应用程序与自动登录功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆