Exemplo n.º 1
0
        // This method will return IsOTPasswordValid for this particular User
        public User ValidatePasswordForUser(User user)
        {
            if (!String.IsNullOrEmpty(user.UserId) && !String.IsNullOrEmpty(user.OTPassword))
            {
                // Concept behind is Generate the OTpassword again and compare the old Password and new Password
                // If this user generate password with in valid time then he will get the same password
                try
                {
                    var currentPassword = GenerateOTP.GeneratePassword(user.UserId);
                    //Compare both passwords
                    if (currentPassword.Equals(user.OTPassword))
                    {
                        user.IsOTPasswordValid = true;
                    }
                    else
                    {
                        //Password is Invalid
                        user.IsOTPasswordValid = false;
                    }

                    return(user);
                }
                catch (Exception e)
                {
                    throw new CustomCodeException(e.Message, ExceptionCode.UN_HANDLED);
                }
            }
            else
            {
                throw new CustomCodeException("UserId, OTPassword and OTPCreatedDateTime cannot be null or empty", ExceptionCode.INVALID_USER_DETAILS);
            }
        }
Exemplo n.º 2
0
        // This method will return OTPassword for this particular UserId
        public User GetPasswordForUser(User user)
        {
            //Ensure UserId is not Null or Empty
            if (!String.IsNullOrEmpty(user.UserId))
            {
                try
                {
                    user.OTPassword = GenerateOTP.GeneratePassword(user.UserId);

                    // Just Added CreatedTime and IsValid for User
                    user.OTPCreatedDateTime = DateTime.Now;
                    user.IsOTPasswordValid  = true;
                    return(user);
                }
                catch (Exception e)
                {
                    throw new CustomCodeException(e.Message, ExceptionCode.UN_HANDLED);
                }
            }
            else
            {
                // CustomCodeException with ExceptionCode
                throw new CustomCodeException("UserId cannot be null or empty", ExceptionCode.USERID_NULL_OR_EMPTY);
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> forgetPassword(ForgetPasswordModel _forgetPasswordModel)
        {
            var         context    = new MongoDataContext();
            AdminMaster logDetails = await new GenericRepository <AdminMaster>(context).GetByCustomAsync(x => x.adEmail != null, "adEmail", _forgetPasswordModel.Email);

            if (logDetails != null)
            {
                Session["fpEmail"] = _forgetPasswordModel.Email;
                var OTP = new GenerateOTP().OTPGenerate(true, 6);
                Session["OtpCode"] = new Cipher().Encrypt(OTP + "&" + logDetails.adEmail);
                // new SMSsend().sendSMS(logDetails.adPhone, "Hi " + logDetails.adName + ", please find the OTP code : " + new GenerateOTP().OTPGenerate(true, 6));
                return(Json(new { obj = logDetails, otpCode = OTP }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { error = "Email Doesn't match." }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public IActionResult generateOTP([FromBody] GenerateOTP otp)
        {
            try
            {
                string OTPValue = Common.GenerateOTP();

                SMSResponse results = new SMSResponse();

                var message = "";

                //otp.emailorPhone = "+14087224019";

                string SaveOtpValue = Data.User.GenerateOTP(OTPValue, otp);

                if (SaveOtpValue == "Success")
                {
                    results = SmsNotification.SendMessage(otp.phone, "Hi User, your OTP is " + OTPValue + " and it's expiry time is 15 minutes.");

                    string status = results.messages[0].status.ToString();

                    if (status == "0")
                    {
                        message = "Message sent successfully.";
                    }
                    else
                    {
                        string err = results.messages[0].error_text.ToString();
                        message = err;
                    }


                    return(StatusCode((int)HttpStatusCode.OK, new { message }));
                }

                else
                {
                    return(StatusCode((int)HttpStatusCode.InternalServerError, new { ErrorMessage = SaveOtpValue }));
                }
            }

            catch (Exception e)
            {
                string SaveErrorLog = Data.Common.SaveErrorLog("generateOTP", e.Message.ToString());

                return(StatusCode((int)HttpStatusCode.InternalServerError, new { ErrorMessage = e.Message.ToString() }));
            }
        }
Exemplo n.º 5
0
        public static string GenerateOTP(string OTPValue, [FromBody] GenerateOTP otp)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@OTPValue", OTPValue));
            parameters.Add(new SqlParameter("@phone", otp.phone));
            parameters.Add(new SqlParameter("@otpType", otp.otpType));
            parameters.Add(new SqlParameter("@role", otp.role));
            try
            {
                string ConnectionString = Common.GetConnectionString();

                string rowsAffected = SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "spGenerateOTP", parameters.ToArray()).ToString();
                return(rowsAffected);
            }
            catch (Exception e)
            {
                throw e;
            }
        }