makeMysqlNativePassword function
Hash password using 4.1+ method (SHA1)
Implementation
List<int> makeMysqlNativePassword(List<int>? scrambler, String? password) {
if (password == null) return [];
// SHA1(password)
final shaPwd = sha1.convert(utf8.encode(password)).bytes;
// SHA1(SHA1(password))
final shaShaPwd = sha1.convert(shaPwd).bytes;
final bytes = List<int>.from(scrambler!)..addAll(shaShaPwd);
// SHA1(scramble, SHA1(SHA1(password)))
final List<int> hash = sha1.convert(bytes).bytes;
// XOR(SHA1(password), SHA1(scramble, SHA1(SHA1(password))))
for (int i = 0; i < hash.length; i++) hash[i] ^= shaPwd[i];
return hash;
}