0

此代码不起作用:

select * 
         from persons 
         where lower(email) = lower({email}) 
         and (password = crypt('{password}', password))
         and approved = 1
         and now() between start_date and coalesce(end_date, current_timestamp );

我必须设置哈希的代码工作正常:

Insert into persons (
          person_id
 ,        name_first
 ,        name_last
 ,        email
 ,        phone
 ,        username
 ,        password
 ,        start_date
 ,        approved
 ,        superuser)
      values
      (
        nextval('PERSON_ID_SEQ')
 ,        {name_first}
 ,        {name_last}
 ,        {email}
 ,        {phone}
 ,        'username'
 ,        crypt('{password}', gen_salt('md5'))
 ,        now()
 ,        0
 ,        0
        )

但我似乎无法正确检查输入密码的哈希值。我想在 where 子句中进行检查,以便在匹配时返回 people 行。

在此先感谢马丁

4

1 回答 1

0

将问题简化为更小的问题...查看 select crypt('{password}', 'hello') 得到什么,以及表中的任何内容是否匹配。

此外,日期比较看起来不是一个好主意,因为它假设对两个不同的时变表达式进行瞬时/原子评估。

除非出于某种原因,该列使用区分大小写的排序规则,否则将电子邮件显式小写有点愚蠢......

于 2014-10-10T20:28:19.800 回答