如何保持用户登录始终“与服务器连接" [英] How to keep user Logged-In always "Connected with Server"

查看:46
本文介绍了如何保持用户登录始终“与服务器连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我希望用户保持登录状态意味着在成功登录后始终连接到服务器(就像 Facebook 应用程序一样).我试图用谷歌搜索这个,但没有找到任何正确的逻辑.许多网站建议使用 SharedPreference 但保留用户的登录凭据.在 SheredPreference 上不是一个好主意,并且没有提供任何答案以保持与服务器的连接.我有点坚持这个想法.我只需要逻辑来实现这一点.欢迎提供任何建议和示例代码.

I'm working on an App, where I wanted the user to keep logged-in means always connected to the server after successful login(just like facebook app). I tried to google this but did not found any correct logic of this. Many website suggests to use SharedPreference but keeping the user's login cred. on SheredPreference is not good idea and did not provide any answer to stay connected to the server. I'm kinda stuck with this idea. I just need logic to implement this. Any suggestions and example code are welcome.

我是安卓菜鸟.

推荐答案

将用户的凭据存储在设备上并不是一种好的设计方式.您可以存储 Hash 密码,这也被拒绝作为良好的应用程序设计技术.据 facebook 和 google 称,这些科技巨头使用 Authentication 令牌登录-注销.用户登录服务器后,将为特定用户生成令牌,然后将其存储在您的设备和服务器上.下次用户访问应用程序时,已发出请求以检查令牌是否有效,如果有效 - 否则不会授予访问权限.

Storing user's credentials on device is not a good way of designing. You can store the Hash password, which is also denied as good application design technique. According to the facebook and google these tech giants use Authentication token login-logout. Once the user log in server generate token for particular user which is then stored on your device as well as the server. Next time user come to App a request has been made to check the token is valid or not, if valid - access granted else not.

此流程的基本设计

教程:

这篇关于如何保持用户登录始终“与服务器连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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