如何使用安全存储在flutter中存储用户名和密码

发布于 2025-01-15 02:40:01 字数 847 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2025-01-22 02:40:01

正如文档所说

  • 钥匙串用于 iOS
  • Android 使用 AES 加密。 AES 密钥使用RSA 进行加密,并且 RSA 密钥存储在 KeyStore

Keystore由系统管理,安全。如果保存密码很重要,您可以使用此选项。
但是,始终建议不要在客户端存储密码,而是保存一些身份验证密钥(如 JWT 令牌等)来对用户进行身份验证。

As the docs say

  • Keychain is used for iOS
  • AES encryption is used for Android. AES secret key is encrypted with RSA and RSA key is stored in KeyStore

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.

居里长安 2025-01-22 02:40:01

有一个名为 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 like Remember Me then it is useful to store the username and the password.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文