password static method
Creates a QVar containing a password hash using the specified hashing algorithm.
MD5, SHA-1, SHA-256, SHA-512, and HMAC (SHA-256) are supported.
password
The password string to hash.
type
The hashing algorithm to use (default is HashType.md5).
hmacKey
The key for HMAC hashing (default is 'unknown_default_key').
Implementation
static QVar password(
String password, {
HashType type = HashType.md5,
String hmacKey = 'unknown_default_key',
}) {
var hash = '';
switch (type) {
case HashType.md5:
hash = md5.convert(utf8.encode(password)).toString();
break;
case HashType.sha1:
hash = sha1.convert(utf8.encode(password)).toString();
break;
case HashType.sha256:
hash = sha256.convert(utf8.encode(password)).toString();
break;
case HashType.sha512:
hash = sha512.convert(utf8.encode(password)).toString();
break;
case HashType.HMAC:
var key = utf8.encode(hmacKey);
var hmacSha256 = Hmac(sha256, key);
hash = hmacSha256.convert(utf8.encode(password)).toString();
break;
}
return QVar(hash);
}