scala - How to return only if a condition is true? -


I still have scala and functional programming hanging.

I am trying to implement an authentication method, but I want to return only if the password matches hash and I am not sure how to do it.

Please forgive the code below, I still have my head functional. Hopefully, I have clarified what I want to do. I only want to return one result, if and only if passwords match the password provided, I want to do nothing to do this met.

  Def authentication (name: string, password: string): option [member] = {db. Connection with {inserted c = & gt; SQL ("Select from member, where less (username) = {member name}"). ('Username' -> name.low lowercase ()) .as (member.member single opt) if (BCRT.CCPA (password, member .member.password)) {member. I am using singleframe and I am playing PlayFramework and Anorm. But, I think this is more of a normal Scala question.   

as (member member .singleOpt) a Option [member] returns. You can filter a option like any archive, which will allow you to filter a user with bad credentials.

  Def proof (name: string, password: string): option [member] = {DB.withConnection {implicit c = & gt; SQL ("Select from member, where short (username) = {username}"). ('Username - & gt; name. Lower lower case) .as (member .member single opatt). Internal function of filter (member = & gt; BCrypt Checkpw (password, member.password))}}  

filter will be called only if The member is found . If BCrypt.checkpw (password, member password) is incorrect, then some (member) will be none , therefore certified Do <


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -