我试图在 Griffon 中加密密码,但我不知道该怎么做。通常我会在另一种语言中使用 md5,但是在 griffon 中呢?
这是我的一些代码:
if (sql.firstRow("SELECT userID FROM tbluser WHERE userID = ${model.userID}") != null) {
// usually in SQL like this
user.executeUpdate("UPDATE tbluser SET username = ${model.username}, password = md5(${model.password}), level = ${model.level} WHERE userID = ${model.userID}")
edt {
int index = model.listUser.findIndexOf{it['userID'] == model.userID}
model.listUser[index] += [username: model.username, password: model.password, level: model.level] --> how to do md5 here?
}
} else {
user.add(userID: model.userID, username: model.username, password: model.password, level: model.level) --> and here?
edt { model.listUser << [userID: model.userID, username: model.username, password: model.password, level: model.level] }
}
我只是得到一个关于它的示例代码并且它有效。
这里的代码:
import java.security.MessageDigest
String generateMD5(String s) {
MessageDigest digest = MessageDigest.getInstance("MD5")
digest.update(s.bytes);
return new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
}
对于我的情况:generateMD5(model.password)