diff --git a/helpers/authenticationHelpers.go b/helpers/authenticationHelpers.go index 8852dbb..311978d 100644 --- a/helpers/authenticationHelpers.go +++ b/helpers/authenticationHelpers.go @@ -15,19 +15,19 @@ func RegisterUser(db *sqlx.DB, username string, password string, password2 strin return model.User{}, errors.New("you have to enter a value") } - if !checkUserPasswords(password, password2) { + if !CheckUserPasswords(password, password2) { return model.User{}, errors.New("the two passwords do not match") } - if !checkUserEmail(email) { + if !CheckUserEmail(email) { return model.User{}, errors.New("you have to enter a valid email address") } - if checkUsernameExists(db, username) { + if CheckUsernameExists(db, username) { return model.User{}, errors.New("the username is already taken") } - pw_hash, err := hashPassword(password) + pw_hash, err := HashPassword(password) if err != nil { panic("password hashing failed") } @@ -38,20 +38,20 @@ func RegisterUser(db *sqlx.DB, username string, password string, password2 strin return model.User{Username: username, UserId: id, Email: email, PwHash: pw_hash}, err } -func checkUserPasswords(password, password2 string) bool { +func CheckUserPasswords(password, password2 string) bool { return password == password2 } -func checkUsernameExists(db *sqlx.DB, username string) bool { +func CheckUsernameExists(db *sqlx.DB, username string) bool { _, err := GetUserId(db, username) return err == nil } -func checkUserEmail(email string) bool { +func CheckUserEmail(email string) bool { return strings.Contains(email, "@") } -func hashPassword(password string) (string, error) { - bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10) return string(bytes), err } diff --git a/helpers/helpers.go b/helpers/helpers.go index 6f22afc..d0b6dc6 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -13,11 +13,6 @@ import ( "golang.org/x/crypto/bcrypt" ) -func HashPassword(password string) (string, error) { - bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) - return string(bytes), err -} - func CheckPasswordHash(password, hash string) bool { err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) return err == nil @@ -31,15 +26,6 @@ func EmptyUserPass(username, password string) bool { return strings.Trim(username, " ") == "" || strings.Trim(password, " ") == "" } -func CheckUserPasswords(password, password2 string) bool { - return password == password2 -} - -func CheckUsernameExists(db *sqlx.DB, username string) bool { - _, err := GetUserId(db, username) - return err == nil -} - func ValidatePassword(db *sqlx.DB, username, password string) bool { var pw_hash string err := db.QueryRow("select pw_hash from user where username = ?", username).Scan(&pw_hash) @@ -50,10 +36,6 @@ func ValidatePassword(db *sqlx.DB, username, password string) bool { return CheckPasswordHash(password, pw_hash) } -func CheckUserEmail(email string) bool { - return strings.Contains(email, "@") -} - func GetTypedDb(c *gin.Context) *sqlx.DB { db := c.MustGet("db").(*sqlx.DB) return db