I'm writing a function in my User
class (which inherits from ProtoUser
) to bootstrap an admin user for my Scala Lift application:
def generateAdminUser():Boolean = {
if (User.findAll(By(User.admin, true)).length == 0) {
val pw = Props.get("firstadmin.password") openOr "hilariouslybadpassword"
val admin = User.create
.lastName(Props.get("firstadmin.lastName") openOr "Lady")
.firstName(Props.get("firstadmin.firstName") openOr "DeFalt")
.email(Props.get("firstadmin.email") openOr "newinstall@mydomain.org")
.validated(true)
.setPasswordFromListString(pw::Nil)
.admin(true)
.saveMe
} else {
false
}
}
Everything seems to be being save except for the password. When I look at the database:
id lastname firstname email locale timezone password_pw password_slt biography validated uniqueid superuser admin_c
1 Lady DeFalt testemail@gmail.com en_US US/Pacific * AE3MQZIX2KUB2ZMR 1 V25VPDIV43BW4HAATP1XMMV152PEWX3L 0 1
The *
is clearly wrong (signing up through the normal code path proves this out: it should be a salted hash of the pw), but I'm not getting anything in my console.devmode.log
, nor on my console. I'm attempting to be able to programmatically add users, but I'm not sure why this is failing? Being pretty new to Scala I'm not sure the best way to diagnose this: I've followed the code pathway as much as I can, but am a bit lost in the maze of ProtoUser/MegaProtoUser/etc.
Do you have firstadmin.password
set in your properties file?
I haven't used ProtoUser
myself, but looking at the code - in the setFromAny
method on PasswordField
, it looks like the list needs to have the password twice in order to validate and hash.
Something like this may help:
setPasswordFromListString(pw::pw::Nil)
Also, there is a default minimum length of the password which is 5
characters. If validation fails, it seems it will default to a default value.