There are multiple option to hash password, But BCrypt I found secure and keep you away from brute force attack.
Why not just use good MD5, SHA1 or SHA256?
MD5, SHA1 and SHA256 was not created for password hashing to begin with. They were created to calculate a digest for a huge amount of data where performance is high priority. This means that they are perfect for ensuring the integrity of data but very bad for hashing passwords. Because they are fast by nature means that hashed passwords can be cracked using brute force attacks very easily.
Why BCrypt ?
Bcrypt has a built in work factor which gives you the possibility to determine how expensive the hash function has to be. This means that you can make the hashing function slower while computers gets faster.
It will be a nightmare for a potential attacker to use brute force to crack your passwords if they get hold of a database dump.
How user it in Play 2.x ?
Add a dependency in build.sbt for jbcrypt:
Sample Code (HashingPassword.scala)
Why not just use good MD5, SHA1 or SHA256?
MD5, SHA1 and SHA256 was not created for password hashing to begin with. They were created to calculate a digest for a huge amount of data where performance is high priority. This means that they are perfect for ensuring the integrity of data but very bad for hashing passwords. Because they are fast by nature means that hashed passwords can be cracked using brute force attacks very easily.
Why BCrypt ?
Bcrypt has a built in work factor which gives you the possibility to determine how expensive the hash function has to be. This means that you can make the hashing function slower while computers gets faster.
It will be a nightmare for a potential attacker to use brute force to crack your passwords if they get hold of a database dump.
How user it in Play 2.x ?
Add a dependency in build.sbt for jbcrypt:
name := """Play-Neo4j""" version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayScala) scalaVersion := "2.11.7" libraryDependencies ++= Seq( jdbc, cache, ws, "org.mindrot" % "jbcrypt" % "0.3m", "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test) resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Sample Code (HashingPassword.scala)
package com.LifeTweet.example import org.mindrot.jbcrypt.BCrypt /** * Created by sumit on 4/30/16. * Hashing Password Using BCrypt * */object HashingPassword { def getHash(str: String) : String = { BCrypt.hashpw(str, BCrypt.gensalt()) } def checkHash(str: String, strHashed: String): Boolean = { BCrypt.checkpw(str,strHashed) } }