Skip to main content

How to Encrypt and Store Password in Flutter?

The shared_preferences package in Flutter provides a way for applications to store key-value pairs persistently. This can be useful for storing user preferences, application state, or any other data that you need to keep around between application launches. However, it stores data as blank text which is not secure enough for storing sensitive data like passwords.

Storing passwords securely is a must for any application that deals with sensitive data. There are many ways to do this, but in this snippet, we’ll focus on how to store passwords securely in Flutter.

There are two main ways to store passwords securely in Flutter: using the flutter_secure_storage package or encrypting the password yourself. We will focus on using flutter_secure_storage.

The flutter_secure_storage package is the easiest way to store passwords securely in Flutter. It uses the platform’s built-in security features to encrypt and store your passwords.

import 'package:flutter_secure_storage/flutter_secure_storage.dart';

final storage = new FlutterSecureStorage();

//save password
String password = "@#43nasASDOLC";
await storage.write(key: "password", value: password );

//read password
String pass = await "password");

By continuing to use the site, you agree to the use of cookies.