Пример #1
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()
}
Пример #2
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")
}
Пример #3
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")
}