3 ms·
hashPassword, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) _, err = db.Exec("INSERT INTO users(usrname, password) VALUES(?, ?)",
by taspeotis 10y ago
hashPassword, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
_, err = db.Exec("INSERT INTO users(usrname, password) VALUES(?, ?)", username, password)
I'm not a Go expert. Doesn't this:
1) ignore an error, if any? And then
2) ignore hashPassword and just insert the non-hashed password into the database?
It looks like if someone follows along from home they'll get a syntax error from "usrname" but let's say they fixed that...
The code at the bottom of the article doesn't seem to suffer from the latter issue, but still suffers from the former.
- afghanPower 10y agoSeems like the author went a little too fast here. Should definitely insert the hashed password into the db. edit: Otherwise, great read! Hoping for more.
- stygiansonic 10y agoYeah, it seems like a typo. The "Signup Page" example doesn't use `hashPassword` but in the "entire source code" example at the bottom, it does properly use `hashedPassword` in the statement. (But still ignores any error from `bcrypt.GenerateFromPassword`)
- lllorddino 10y agoFixed and fixed. There were more bugs in it but glad you pointed this out or else I may have never fixed it.