本文整理汇总了Golang中github.com/varding/wetalk/modules/models.User.Password方法的典型用法代码示例。如果您正苦于以下问题:Golang User.Password方法的具体用法?Golang User.Password怎么用?Golang User.Password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/varding/wetalk/modules/models.User
的用法示例。
在下文中一共展示了User.Password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegisterUser
// register create user
func RegisterUser(user *models.User, username, email, password string, locale i18n.Locale) error {
// use random salt encode password
salt := models.GetUserSalt()
pwd := utils.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 = utils.EncodeMd5(user.Email)
// Use username as default nickname.
user.NickName = user.UserName
//set default language
if locale.Lang == "en-US" {
user.Lang = setting.LangEnUS
} else {
user.Lang = setting.LangZhCN
}
//set default avatar
user.AvatarType = setting.AvatarTypeGravatar
return user.Insert()
}
示例2: SaveNewPassword
// set a new password to user
func SaveNewPassword(user *models.User, password string) error {
salt := models.GetUserSalt()
user.Password = fmt.Sprintf("%s$%s", salt, utils.EncodePassword(password, salt))
return user.Update("Password", "Rands", "Updated")
}