Пример #1
0
func VerifyPassword(rawPwd, encodedPwd string) bool {
	var salt, encoded string
	if len(encodedPwd) > 11 {
		salt = encodedPwd[:10]
		encoded = encodedPwd[11:]
	}
	return tools.EncodePassword(rawPwd, salt) == encoded
}
Пример #2
0
func RegisterUser(user *models.User, username, email, password string) error {
	// use random salt encode password
	salt := models.GetUserSalt()
	pwd := tools.EncodePassword(password, salt)
	user.UserName = strings.ToLower(username)
	user.Email = strings.ToLower(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 = tools.EncodeMd5(user.Email)

	// Use username as default nickname.
	user.NickName = user.UserName
	//设置用户默认激活
	user.IsActive = true

	return user.Insert()
}
Пример #3
0
func ConnectUpdateUser(user *models.User, password string) error {
	salt := models.GetUserSalt()
	pwd := tools.EncodePassword(password, salt)
	user.Password = fmt.Sprintf("%s$%s", salt, pwd)
	return user.Update("UserName", "Password")
}
Пример #4
0
func SaveNewPassword(user *models.User, password string) error {
	salt := models.GetUserSalt()
	user.Password = fmt.Sprintf("%s$%s", salt, tools.EncodePassword(password, salt))
	return user.Update("Password", "Rands", "Updated")
}