Example #1
0
// update user password with user id and new password
func UpdatePassword(id int64, newPassword string) error {
	u := new(User)
	u.Salt = utils.Md5String(newPassword)[8:24]
	u.Password = utils.Sha256String(newPassword + u.Salt)
	if _, err := vars.Db.Cols("password,salt").Where("id = ?", id).Update(u); err != nil {
		log.Println("Db|UpdatePassword|%d|%s", id, err.Error())
		return err
	}
	return nil
}
Example #2
0
// create new token with user id and expiration duration
func CreateToken(user, expire int64) (*Token, error) {
	t := &Token{
		UserId:     user,
		ExpireTime: time.Now().Unix() + expire,
	}
	t.Token = utils.Md5String(fmt.Sprintf("%d,%d", t.UserId, t.ExpireTime))
	if _, err := vars.Db.Insert(t); err != nil {
		log.Println("Db|CreateToken|%v|%s", t, err.Error())
		return nil, err
	}
	return t, nil
}