0

i wanted to use bcryptjs on angualr15. it didnt work. it throws error referring to polyfills.

I made a reproducation example:

when going for ng reproduction project --skip-git

then in the cli go for: npm i bcryptjs or npm i argon2

for simplicity lets assume we use bcryptjs for now.

then in then app.compnent.ts go for something like:

let password:string="anypasswordthatssave&5$5"

let salt:string=bcrypt.genSalt(10)

let hashedpassword:string=bcrypt.hashSync(password,salt)

then in the app.component.html

{{password}}<br>{{salt}}<br>{{hashedpassword}}

it complains about polyfill issues.

Any idea..about it? what i did wrong or what i can do to get bcrypt to work? because to me its seem like it has gotten so beginner unfriendly..

this problem is adressed to alot of webpackages.

My current solution is writing an hash class for on my own.. but thats a horrible alternative in comparison to the benefits of using hashing webpackahed like bcrypt.

Buttomline: i just started working with angular a few month ago. In terms of an issue.
I'm really looking forward to your response. There is always the option of me having misconceptions. being a beginner makes it currently really hard for me.
sadly i cannot fix the issue with what i know. also couldnt find any tutorial or reference in the angular docu i could work with.

if there is a link just anywhere.. that adresses this situation in the best possbile way even a solution. i would love to read it . please dont shut the issue down.. after i did my rerally best to provide code to reproduce the issue.

I was trying to use becryptjs to hash password string.

also I tried to add and manipulate the webapackage and polyfills (which oboith dont exist in angular 15 no more)

researched alot.

my current solution is using my own hashing and dehashing class.

Mathanuel
  • 1
  • 3
  • 1
    Generally, you wouldn't use BCrypt on a frontend application like this because running encryption on passwords should be done on a backend service. Because of this, BCrypt isn't designed to run on a browser (hence your polyfill errors). If this is just to play around with it (and not for any real project) then you can edit your post with the exact error(s) you are getting and there may be polyfills for what you need. Edit: I just looked, I am not sure it's possible to run BCrypt in a browser because I think it needs system dependencies (which would not be polyfillable) – Chris Gilardi Apr 19 '23 at 16:37
  • 1
    Thanks for your answer! Well it worked back then in previous angular versions. I get ur point though. But then what would i use for hashing from client to backend? i dont want to send the eg plaintext passwords – Mathanuel Apr 19 '23 at 17:18
  • @Mathanuel have you found a solution for this? I have been away from angular for 2years now and got a new project to work on. I also used to encrypt plain passwords using bcryptjs back in day, – Githendra McShane Apr 26 '23 at 07:35
  • Sadly no. I'm still doing research on it . please let me know if you find a way to accomplish that. – Mathanuel Apr 27 '23 at 18:54

0 Answers0