cdepillabout / password

datatypes and functions for easily working with passwords in Haskell
http://hackage.haskell.org/package/password
55 stars 16 forks source link

No type to convert Text back to PasswordHash Bcrypt, which is a required type parameter in the Data.Password.Bcrypt (checkPassword) #77

Closed ruile closed 6 months ago

ruile commented 6 months ago

Context Hash a password, and store it in a Postgres database using postgresql-simple library

Intent To retrieve the hashed password from the database, and compare it with a user submitted password using the checkPassword function.

Issue Database only accepts ::Text. Hence initial password must be converted from ::PasswordHash Bcrypt to ::Text using unPasswordHash.

However, there is no way in the library to convert the hashed password from the database back to type ::PasswordHash Bcrypt for usage with the checkPassword function, which has type signature :: Password -> PasswordHash Bcrypt -> PasswordCheck.

How can I achieve my intent? Or am I missing something here.

Thank you :)

Vlix commented 6 months ago

The PasswordHash data constructor is free to use, so you can construct your own PasswordHash from any Text

hashFromDB :: PasswordHash Bcrypt
hashFromDB = PasswordHash textYouGotFromDB

Or am I not understanding your issue?

ruile commented 6 months ago

Hi Vlix, thank you for helping a Haskell newbie like me! I embarrassingly mixed up PasswordHash constructor with the PasswordHash a newtype. Now I get it 😄

Vlix commented 6 months ago

No worries :) Good luck on your Haskell journey!