func (ctx *MgoUserCtx) GeneratePassword(password string) membership.Password { if len(password) == 0 { password = secure.RandomString(16) } pwd := membership.Password{} pwd.InitAt = time.Now() pwd.Salt = secure.RandomToken(32) ctx.pwdHash.Write([]byte(password)) ctx.pwdHash.Write(pwd.Salt) pwd.Hashed = ctx.pwdHash.Sum(nil) ctx.pwdHash.Reset() return pwd }
func (ctx *MgoUserCtx) ValidConfirmCode(id model.Identifier, key, code string, regen, del bool) (bool, error) { tid, ok := id.(mtoy.ID) if !ok { return false, membership.ErrInvalidId } acc := Account{} err := ctx.userColl.FindId(tid.ObjectId).One(&acc) if err != nil { return false, err } ok = acc.ConfirmCodes[key] == code change := bson.M{} if del { change["$unset"] = bson.M{"confirmcodes." + key: false} } else { change["$set"] = bson.M{"confirmcodes." + key: secure.RandomString(32)} } ctx.userColl.UpdateId(tid.ObjectId, change) return ok, err }