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() }
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") }
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") }