Search code examples
postgresqlpgcrypto

how to test pass with pgcrypto (with realm - digesthashmethod)


I try to check password using pgcrypt

I can only use two methods (database limitation)

  • HtPasswdHashMethod
  • HtDigestHashMethod

I can use the first method:

SELECT crypt('mypass',value)=value FROM passwords where person=1

but I have to change the method into second one - HtDigestHashMethod

In datatabase passwords looks like (changed - not real one):

first method: uXifOBs5A0l6w
second method: myrealm:8f24d836943973c5c3e47bd909080b49

how to check password with myrealm


Solution

  • The solution:

    You have to create hash like this:

    md5('User Name:myrealm:mypass')
    

    so my phpcode looks like:

    $sqlQuery="SELECT 'myrealm:'".md5('$username:myrealm:$password')."'=value FROM passwords WHERE person=1";