Flutter密码安全处理插件secure_password_utility的使用
Flutter密码安全处理插件secure_password_utility的使用
本密码工具在Flutter应用中鼓励使用强密码。
当调用checkWeakPassword
方法时,将返回一个布尔值。弱密码(如password123或常见单词)也将返回false。
checkWeakPassword
方法通过确保密码长度超过9个字符来验证输入。它还会确认输入包含数字和特殊字符、小写字母和大写字母的组合。
一旦在UI中展示了这些条件,此函数将强制执行验证。
使用
示例代码
import 'package:secure_password_utility/secure_password_utility.dart';
void main() {
// 在您的Flutter应用程序中单独调用这些方法
checkPasswordStrength('#sh0klmNZaDf[@52](/user/52)', 15);
createPassword(16);
createProductKey(20);
}
// 验证密码强度语法: SecurePasswordGateway.checkWeakPassword('yourSamplePassword', lengthOfPasswordString);
// 注意:确保要验证的密码长度至少为15个字符。
// 检查密码强度。它返回一个布尔值
Future<bool> checkPasswordStrength(String password, int passwordLength) async {
var passcodeStrength = false;
await SecurePasswordGateway().checkWeakPassword(password, passwordLength)
.then((value) => {
passcodeStrength = value
});
print('Strong password is $passcodeStrength');
return passcodeStrength;
}
// 生成强密码语法: SecurePasswordGateway.createPassword(lengthOfPasswordString);
// 注意:密码长度必须大于15。
// 以特定长度创建新密码
Future<dynamic> createPassword(int passwordLength) async {
var createdPassword = '';
await SecurePasswordGateway().generateStrongPassword(passwordLength)
.then((value) => createdPassword = value);
print('generated strong password is $createdPassword');
return createdPassword;
}
// 生成产品密钥语法: SecurePasswordGateway.generateProductKey(25);
// 注意:密码长度必须是16到100之间的4或5的倍数,例如16或25
String createProductKey(int productKeyLength) {
var res = SecurePasswordGateway().generateProductKey(productKeyLength);
print('PRODUCT KEY IS::::: $res');
return res;
}
更多关于Flutter密码安全处理插件secure_password_utility的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复