Rename StringUtil#encrypt() to sha1().

This commit is contained in:
takezoe
2013-07-11 11:09:30 +09:00
parent 0170f9b44a
commit f104fab593
5 changed files with 7 additions and 7 deletions

View File

@@ -70,7 +70,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
val userName = params("userName") val userName = params("userName")
getAccountByUserName(userName).map { account => getAccountByUserName(userName).map { account =>
updateAccount(account.copy( updateAccount(account.copy(
password = form.password.map(encrypt).getOrElse(account.password), password = form.password.map(sha1).getOrElse(account.password),
mailAddress = form.mailAddress, mailAddress = form.mailAddress,
url = form.url)) url = form.url))
@@ -93,7 +93,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
post("/register", newForm){ form => post("/register", newForm){ form =>
if(loadSystemSettings().allowAccountRegistration){ if(loadSystemSettings().allowAccountRegistration){
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url) createAccount(form.userName, sha1(form.password), form.mailAddress, false, form.url)
updateImage(form.userName, form.fileId, false) updateImage(form.userName, form.fileId, false)
redirect("/signin") redirect("/signin")
} else NotFound } else NotFound

View File

@@ -25,7 +25,7 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
post("/signin", form){ form => post("/signin", form){ form =>
val account = getAccountByUserName(form.userName) val account = getAccountByUserName(form.userName)
if(account.isEmpty || account.get.password != encrypt(form.password)){ if(account.isEmpty || account.get.password != sha1(form.password)){
redirect("/signin") redirect("/signin")
} else { } else {
session.setAttribute("LOGIN_ACCOUNT", account.get) session.setAttribute("LOGIN_ACCOUNT", account.get)

View File

@@ -47,7 +47,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
}) })
post("/admin/users/_new", newForm)(adminOnly { form => post("/admin/users/_new", newForm)(adminOnly { form =>
createAccount(form.userName, encrypt(form.password), form.mailAddress, form.isAdmin, form.url) createAccount(form.userName, sha1(form.password), form.mailAddress, form.isAdmin, form.url)
updateImage(form.userName, form.fileId, false) updateImage(form.userName, form.fileId, false)
redirect("/admin/users") redirect("/admin/users")
}) })
@@ -61,7 +61,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
val userName = params("userName") val userName = params("userName")
getAccountByUserName(userName).map { account => getAccountByUserName(userName).map { account =>
updateAccount(getAccountByUserName(userName).get.copy( updateAccount(getAccountByUserName(userName).get.copy(
password = form.password.map(encrypt).getOrElse(account.password), password = form.password.map(sha1).getOrElse(account.password),
mailAddress = form.mailAddress, mailAddress = form.mailAddress,
isAdmin = form.isAdmin, isAdmin = form.isAdmin,
url = form.url)) url = form.url))

View File

@@ -59,7 +59,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = { private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = {
getAccountByUserName(username).map { account => getAccountByUserName(username).map { account =>
account.password == encrypt(password) && hasWritePermission(repository.owner, repository.name, Some(account)) account.password == sha1(password) && hasWritePermission(repository.owner, repository.name, Some(account))
} getOrElse false } getOrElse false
} }

View File

@@ -2,7 +2,7 @@ package util
object StringUtil { object StringUtil {
def encrypt(value: String): String = { def sha1(value: String): String = {
val md = java.security.MessageDigest.getInstance("SHA-1") val md = java.security.MessageDigest.getInstance("SHA-1")
md.update(value.getBytes) md.update(value.getBytes)
md.digest.map(b => "%02x".format(b)).mkString md.digest.map(b => "%02x".format(b)).mkString