[ColdBox 3.5.1] hash password

I have this code:

var emailBean = emailService.new(ENTITYNAME=“email”);
emailBean.setRecupero(“ciccioformaggio”);
populateModel(model=emailBean,exclude=“id”);
emailService.save(emailBean);

How can I hash the password?

I have two forms email and password…

You want to hash an email password?

Jason Durham

Yes.

I have solved!!!

Care to share the solving for the list? :slight_smile:

Thanks!

~Brad

Sure!!!

function save(event){
var emailBean = emailService.new(ENTITYNAME=“email”);
var hashPassword = hash(rc.password,“SHA-512”);
emailBean.setPassword(hashPassword);
populateModel(model=emailBean,exclude=“id”);
prc.validationResults = validateModel(emailBean);
if( prc.validationResults.hasErrors() ){
getMyPlugin(“MessageBox”).error(messageArray=prc.validationResults.getAllErrors());
setNextEvent(event=“email.viewForm”,persist=“email,recupero”);
}
else{
emailService.save(emailBean);
getMyPlugin(“MessageBox”,true).info(“Info Message”);
setNextEvent(“email.index”);
}
}

You might consider at least salting these hashed passwords. If you are not familiar with salting here are some quick Google results I found:

http://stackoverflow.com/questions/7669374/coldfusion-salting-my-hash

http://thomashunter.name/blog/password-encryption-hashing-salting-explained/
http://www.adayinthelifeof.nl/2011/02/02/password-hashing-and-salting/

Many thanks!!!