Beispiel #1
0
// register create user
func RegisterUser(form RegisterForm, user *User) error {
	// use random salt encode password
	salt := utils.GetRandomString(10)
	pwd := utils.EncodePassword(form.Password, salt)

	user.UserName = form.UserName
	user.Email = form.Email

	// save salt and encode password, use $ as split char
	user.Password = fmt.Sprintf("%s$%s", salt, pwd)

	// save md5 email value for gravatar
	user.GrEmail = utils.EncodeMd5(form.Email)

	return NewUser(user)
}
Beispiel #2
0
// compare raw password and encoded password
func VerifyPassword(rawPwd, salt, encodedPwd string) bool {
	return utils.EncodePassword(rawPwd, salt) == encodedPwd
}