-
|
I'm confused about how the sqlpage.hash_password function works. Each time it's called with the same password, it returns visually different strings, looking more like random strings. How then can the newly calculated value be compared with the previously obtained value and stored in the database if they are different? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
short answer
The detailsofficial documentation:
and related examples:
on password hashing :
|
Beta Was this translation helpful? Give feedback.
-
|
I assumed it was a regular hash function that returns the same value for the same string and started building checks based on that assumption, but upon testing, I discovered the hash was changing every time. I hadn't encountered salted hashes before, which are used to store passwords, but I didn't understand where the salt comes from and how I could now compare the stored hashes and the ones retrieved with a new login. From the examples, I understood that this somehow works with the authentication component, but I didn't understand how it does the comparison. I'll keep digging into this. Thank you so much for answering my amateurish questions. |
Beta Was this translation helpful? Give feedback.
-
|
i updated the docs: 34f5d7f |
Beta Was this translation helpful? Give feedback.
-
|
Thanks again. While I was digging around, I noticed that the returned string, in addition to the header, had two parts separated by a $ sign. I assumed that one part depended on the other, which would make everything fall into place. But I couldn't figure out how to use this, since there was no explicit comparison function. From the examples, I began to understand that this was related to the authentication component, meaning that hash comparison is part of its functionality. Previously, I wrote a procedure in pgplsql that was passed a session key and a page path, and it calculated a value that, via the redirect component on the page, redirected to the appropriate page, if necessary. In my case, access to the same page depended on the user's group membership, and I was more accustomed to consolidating the entire analysis into a single server procedure. With the authentication component, I'd have to split the process into two parts: first, check for permissions via the page. Then, using the server procedure, analyze whether the user has access rights to this page based on their group membership. In general, I am now rethinking my approach in light of the new requirements. |
Beta Was this translation helpful? Give feedback.
-
|
That's exactly what I intended. The session key was, of course, the value from the sqlpage.random_string(length) function. The password hash from sqlpage.hash_password(password) was only used for storage in the database and comparison with the hash obtained from the password specified during subsequent logins. However, I didn't expect the hash string to be different for the same password and assumed a simple comparison, which I would perform in my procedure, would be sufficient. In fact, to avoid changing the procedure, I could use a standard hash function, such as SHA-xxx, but that would naturally reduce the level of protection against password guessing. I'm not ready to write my own hash function with a random salt; I have more pressing tasks. Therefore, I'll try to adapt the authentication and access rights verification process to the existing mechanism in SQLPage. Basically, I want to store as much as possible in the database, including pages and settings, because in the future I'd like to reduce the entire application to a translator that could build an interface on the fly based on metadata from the database. SQLPage is currently the closest analog of such an application I know of. |
Beta Was this translation helpful? Give feedback.
-
|
Wow! The last example looks interesting, SQLPage is an amazing application. |
Beta Was this translation helpful? Give feedback.
short answer
sqlpage.hash_passwordis meant to be called only once at the creation of an user account. Passwords are salted with a random string. This makes weak passwords harder to crack even if an attacker gets access to the hash.The
authenticationcomponent is meant to check the password when the user logs in.details
official documentation:
and related examples: