保存 Kivy 应用程序的登录屏幕用户名和密码 [英] Saving login screen username and password for Kivy app

查看:26
本文介绍了保存 Kivy 应用程序的登录屏幕用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发适用于 iOS 和 Android 的 Kivy 应用程序,需要帮助保持用户持续登录,即使在应用程序关闭或终止后也是如此.我正在使用 Parse 来存储用户凭据.

I am working on a Kivy app for iOS and Android and need help with keeping the user persistently logged in, even after the app is closed or killed. I am using Parse to store user credentials.

我已经在 App 类中添加了一个 on_pause 方法,但这只会在应用程序关闭但未终止时保持用户登录状态.是否有安全允许用户使用 Kivy 持续登录的最佳做法,即使在应用程序被终止后也是如此?

I've already added an on_pause method to the App class, but this only keeps the user logged in if the app is closed but not killed. Is there a best practice for securely allowing persistent user login with Kivy, even after an app is killed?

我更喜欢适用于 Android 应用和 iOS 应用的单一 Kivy 解决方案,而无需编辑/添加 iOS 或 Android 特定代码.

I prefer a single Kivy solution that works for both an Android app and an iOS app, without the need to edit/add iOS or Android specific code.

推荐答案

下面是我们最终用来存储登录信息的代码,它使用了 Kivy 的 JsonStore.然后还可以使用 Python 加密库对凭据进行加密.

Below is the code that we ended up using to store the login info, which employs Kivy's JsonStore. The credentials can also then be encrypted using Python encryption libraries.

from kivy.storage.jsonstore import JsonStore

from os.path import join


class AppScreen(ScreenManager):
    data_dir = App().user_data_dir
    store = JsonStore(join(data_dir, 'storage.json'))
    ...
    def login(self):
        username = self.login_username.text
        password = self.login_password.text
        AppScreen.store.put('credentials', username=username, password=password)

这是检索凭据的代码:

try:
    store.get('credentials')['username']
except KeyError:
    username = ""
else:
    username = store.get('credentials')['username']

try:
    store.get('credentials')['password']
except KeyError:
    password = ""
else:
    password = store.get('credentials')['password']

在 .kv 文件中,用户名和密码 TextInput 小部件如下所示:

In the .kv file, the username and password TextInput widgets look like this:

TextInput:
    id: login_username
    text: root.username
    on_enter_key: root.login()

TextInput:
    id: login_password
    text: root.password
    on_enter_key: root.login()

这篇关于保存 Kivy 应用程序的登录屏幕用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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