func (u OtpRestful) verifyUserOtp(request *restful.Request, response *restful.Response, otpType otp.TypeOfOtp) { var secret cr.Secret err := request.ReadEntity(&secret) if err != nil { u.setError(response, http.StatusBadRequest, err) return } data := u.getOtp(request, response) if data == nil { return } ok, err := data.VerifyOtpUserCode(secret.Secret, otpType) res := cr.Match{Match: ok, Message: cr.NoMessageStr} if ok == false && err != nil { res.Message = fmt.Sprintf("%v", err) } response.WriteHeaderAndEntity(http.StatusOK, res) }
func (p PwdRestful) restVerifyPassword(request *restful.Request, response *restful.Response) { var secret secretData err := request.ReadEntity(&secret) tPwd, _ := salt.GenerateSaltedPassword([]byte(secret.Password), password.MinPasswordLength, password.MaxPasswordLength, p.saltStr, -1) pass := password.GetHashedPwd(tPwd) if err != nil { p.setError(response, http.StatusBadRequest, err) return } data := p.getPwdData(request, response) if data == nil { return } err = data.IsPasswordMatch(pass) ok := true if err != nil { ok = false } res := cr.Match{Match: ok, Message: cr.NoMessageStr} if ok == false && err != nil { res.Message = fmt.Sprintf("%v", err) } response.WriteHeaderAndEntity(http.StatusOK, res) }