0

I am trying to insert username and encrypted password pairs into database table using squeryl ORM framework. My code basically looks like the following:

      class SHA1(e: StringExpression[String], m:OutMapper[String]) extends FunctionNode[String]("sha1", Some(m), Seq(e)) with StringExpression[String]

      def sha1(e:StringExpression[String])(implicit m:OutMapper[String]) = new SHA1(e,m)
      transaction{
        val foo = TestUser.userTable insert User("test@domain.com", sha1("password"))
      }

But this does not work. I got an error saying:

type mismatch; found : controllers.SHA1 required: String Error occurred in an application involving default arguments. 

1 Answers1

1

There is a limit to the magic that Squeryl can perform here. Your model class takes a String value for password, and you are passing it a value of type SHA1 (the value that is returned from the sha1 function). The scala compiler isn't going to allow that. There are a couple of options here:

  1. Hash the password before sending it to the db
  2. Insert your User with a null value for the password, then update it in the same transaction with the password hashed via your function
  3. If you are using Squeryl 0.9.6-SNAPSHOT, you might create a SHAString custom type that handles hashing the string when it is sent to the DB

To hash the password before you insert it, look at java.security.MessageDigest and see this answer.

Community
  • 1
  • 1
Dave Whittaker
  • 3,102
  • 13
  • 14
  • Hi Dave, I am already trying to hash the password before sending it to the db. So your 1 and 2 are exactly what I am trying to do. Could you provide some additional help? Thank you. –  Apr 22 '13 at 23:47
  • I've updated the answer with some information on how to hash your password outside of the db before inserting the record. – Dave Whittaker Apr 23 '13 at 13:22
  • You can use the _akka.util.Crypt.sha1()_ method to generate a SHA1 hash. – akkie Apr 24 '13 at 06:23