如何使用安全存储在flutter中存储用户名和密码
我正在使用 flutter 编写应用程序,现在我想使用 安全存储 来存储用户名/密码像这样:
SecureStorageUtil.putString("password", password);
这是一个好的做法吗?或者从不将用户密码存储在客户端应用程序中?我已经从谷歌搜索过,但没有人谈论它。这是 SecureStorageUtil
:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class SecureStorageUtil{
static FlutterSecureStorage _preferences = FlutterSecureStorage();
static Future<String?> getString (String key, {String defValue = ''}) {
return _preferences.read(key:key) ;
}
static Future<void> putString(String key, String value) {
return _preferences.write(key:key, value:value);
}
static Future<void> delString(String key) {
return _preferences.delete(key:key);
}
}
I am using flutter to write an app, now I want to use secure storage to store the username/passowrd like this:
SecureStorageUtil.putString("password", password);
is it a good practice? Or never store the user password in the client app? I already searching from Google but no one talk about it. And this is the SecureStorageUtil
:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class SecureStorageUtil{
static FlutterSecureStorage _preferences = FlutterSecureStorage();
static Future<String?> getString (String key, {String defValue = ''}) {
return _preferences.read(key:key) ;
}
static Future<void> putString(String key, String value) {
return _preferences.write(key:key, value:value);
}
static Future<void> delString(String key) {
return _preferences.delete(key:key);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如文档所说
Keystore由系统管理,安全。如果保存密码很重要,您可以使用此选项。
但是,始终建议不要在客户端存储密码,而是保存一些身份验证密钥(如 JWT 令牌等)来对用户进行身份验证。
As the docs say
Keystore is managed by the system, and the will be secure. You may use this if saving the password is important.
However, its always recommended not to store passwords on the client-side, instead, save some Auth keys like JWT token, etc. to authenticate users.
有一个名为
SharePreferences
的包,它允许您在 ios 和 android 平台上存储任何内容,并且它没有任何问题。我推荐那个包。我希望这会起作用。第二件事是存储密码。如果用户在应用程序中有一个选项,例如记住我
,那么存储用户名和密码会很有用。There is a package named
SharePreferences
that will allow you to store anything on both platforms ios and android and it did not have any kind of issue. I recommend that package. I hope that will work. And the second thing is storing password. If the user have an option in the app likeRemember Me
then it is useful to store the username and the password.