For my express app, I'm tasked with creating an authentication system that uses a 4-digit pin as the password. The code is set up to save and hash the pin along with other user information when adding a new user. Since this is for an in-house server handling a small number of users, efficiency isn't a major concern.
The issue arises when attempting to sign the user back in. By using bcrypt to hash the password, each identical string generates a different hash, making it difficult to fetch the user using WHERE hash=hash
in SQL searches.
One solution could be to retrieve all users and compare hashes using bcrypt's .compare
method, but this isn't sustainable as the user base grows. Another option is to create a custom hashing function, requiring individual salts per user to ensure unique hashes.
Although the challenge lies in fetching the user based on a hashed password, any suggestions or insights would be greatly appreciated.