Regular expression to find bcrypt hash?

后端 未结 4 1205
Happy的楠姐
Happy的楠姐 2021-02-12 22:26

I am looking to find bcrypt hash string using regex (in PowerGrep), in a database.

Tried this regex:

{?A-Za-z_0-9.{60}}?

But no match w

4条回答
  •  無奈伤痛
    2021-02-12 23:04

    According to Wikipedia, bcrypt hashes follow the following format:

    $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy
    \__/\/ \____________________/\_____________________________/
     Alg Cost      Salt                        Hash
    

    Where valid values for each segment are:

    • Alg: 2, 2a, 2b, 2x or 2y
    • Cost: 4-31 (zero-padded to 2 digits)
    • Salt: ./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ x 22
    • Hash: ./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ x 31

    Therefore, a comprehensive regex would look something like the following:

    ^[$]2[abxy]?[$](?:0[4-9]|[12][0-9]|3[01])[$][./0-9a-zA-Z]{53}$
    

提交回复
热议问题