Exemplo n.º 1
0
        public HttpResponseMessage ForgotPassWord(forgotPassword fp)
        {
            Student s = (from cm in db.Students where cm.Email == fp.email select cm).FirstOrDefault();

            if (s != null)
            {
                var hasher = new HMACSHA256(Encoding.UTF8.GetBytes(fp.email));
                var h      = Convert.ToBase64String(hasher.ComputeHash(Encoding.UTF8.GetBytes(fp.email)));

                if (h == fp.passcode)
                {
                    var hasher2 = new HMACSHA256(Encoding.UTF8.GetBytes(fp.newpassword));
                    var h2      = Convert.ToBase64String(hasher2.ComputeHash(Encoding.UTF8.GetBytes(fp.newpassword)));


                    s.Pwd = h2;
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, "Match"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "NotMatch"));
                }
            }

            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "NotDone"));
            }
        }
Exemplo n.º 2
0
        public ActionResult ForgotPassword(forgotPassword fp)
        {
            string message = "";
            bool   status  = false;

            if (fp != null)
            {
                var user = repo.Listele().Where(x => x.email == fp.email).FirstOrDefault();
                user.resetCode = Guid.NewGuid().ToString();
                repo.Guncelle(user);
                // mail göndereceğiz
                SendResetPassword(fp.email, user.resetCode);
                message = "Parola Sıfırlama işlemi başarılı şekilde gerçekleştirildi. Parola sifirlama linki "
                          + fp.email + " adresinize gönderilmiştir.";
                status = true;
            }
            else
            {
                message = "Böyle bir Email mevcut değil";
                status  = false;
            }
            ViewBag.status  = status;
            ViewBag.message = message;
            return(View());
        }
Exemplo n.º 3
0
 public ActionResult ResetPassword(forgotPassword fwd)
 {
     if (ModelState.IsValid)
     {
         var UserEmail = db.Users_Data.Where(m => m.user_email_id == fwd.email).SingleOrDefault();
         if (UserEmail != null && UserEmail.otp_key == fwd.otp_text)
         {
             DateTime startTime = (DateTime)UserEmail.otp_time;
             DateTime endTime   = DateTime.Now;
             TimeSpan span      = endTime.Subtract(startTime);
             if (span.TotalMinutes <= 5)
             {
                 UserEmail.user_web_pwd    = fwd.password;
                 db.Entry(UserEmail).State = EntityState.Modified;
                 db.SaveChanges();
             }
             else
             {
                 ModelState.AddModelError("", "OTP has expired!, Please try again");
             }
             return(View());
         }
         else
         {
             ModelState.AddModelError("", "Please check your OTP");
         }
     }
     return(View("PwdChanged"));
 }
Exemplo n.º 4
0
        public ActionResult forgotPassword(forgotPassword User)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("BadRequest", "Invalid Request!");
            }

            try
            {
                using (Notestash_Database_Entities db = new Notestash_Database_Entities())
                {
                    var emailId = db.tblUsers.FirstOrDefault(e => e.Email == User.Email);
                    emailId.forgotPasswordCode = Guid.NewGuid();
                    db.SaveChanges();
                    changePasswordEmail(emailId.Email, emailId.forgotPasswordCode.ToString());
                    ModelState.AddModelError("Sent", "Link to change password has been sent to your email id.");
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                ModelState.AddModelError("BadRequest", "Invalid Request!");
            }
            return(View());
        }
Exemplo n.º 5
0
        public int resetPasswordFromForget(forgotPassword forgotPassword)
        {
            var userID       = new SqlParameter("@userID", forgotPassword.userID);
            var new_password = new SqlParameter("@newPassword", forgotPassword.Password);
            var result       = uow.sp_LoginUser_Result_.SQLQuery <int>("resetPasswordfromForget_sp @userId,@newPassword", userID, new_password).FirstOrDefault();

            return(result);
        }
Exemplo n.º 6
0
        public ActionResult IdentifyAccount(LoginModel getemail)
        {
            var UserEmail = db.Users_Data.Where(m => m.user_email_id == getemail.email).SingleOrDefault();

            if (UserEmail != null)
            {
                try
                {
                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add(UserEmail.user_email_id);
                    mail.Subject = "Your BPAS Account | Password Reset Action";
                    string password = System.Web.Security.Membership.GeneratePassword(6, 0);

                    /**
                     * Inserting in to Database
                     */
                    UserEmail.otp_key         = password;
                    UserEmail.otp_time        = DateTime.Now;
                    db.Entry(UserEmail).State = EntityState.Modified;
                    db.SaveChanges();


                    mail.Body = "Let's get you back into your account .Please use this one time password: "******" ";

                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Bpas2018");
                    SmtpServer.EnableSsl   = true;

                    SmtpServer.Send(mail);

                    forgotPassword fgt = new forgotPassword();
                    fgt.email = UserEmail.user_email_id;

                    return(View("ResetPassword", fgt));
                }
                catch (Exception ex)
                {
                    log.Debug("checking" + ex);
                }
            }
            else
            {
                ModelState.AddModelError("", "Emaild doesn't exist");
            }


            return(View());
        }
Exemplo n.º 7
0
        public IActionResult forgetPassword(forgotPassword forgotPassword)
        {
            try
            {
                if (forgotPassword.password == "" || forgotPassword.password == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, new { ErrorMessage = "Please enter Password" }));
                }
                else if (forgotPassword.phone == "" || forgotPassword.phone == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, new { ErrorMessage = "Please enter Phone" }));
                }
                else if (forgotPassword.OTPValue == "" || forgotPassword.OTPValue == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, new { ErrorMessage = "Please enter OTPValue" }));
                }



                string row = Data.User.forgotPassword(forgotPassword);

                if (row == "Success")
                {
                    return(StatusCode((int)HttpStatusCode.OK, new { message = "Updated Successfully" }));
                }
                else if (row == "Invalid OTP")
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden, new { errorMessage = "Invalid OTP" }));
                }
                else if (row == "Invalid PhoneNumber")
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden, new { errorMessage = "Invalid PhoneNumber" }));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden, new { ErrorMessage = row }));
                }
            }

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

                return(StatusCode((int)HttpStatusCode.InternalServerError, new { ErrorMessage = e.Message }));
            }
        }
Exemplo n.º 8
0
        public static string forgotPassword([FromBody] forgotPassword forgotPassword)
        {
            var encryptPassword = Common.EncryptData(forgotPassword.password);

            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@OTPValue", forgotPassword.OTPValue));
            parameters.Add(new SqlParameter("@phone", forgotPassword.phone));
            parameters.Add(new SqlParameter("@password", encryptPassword));

            try
            {
                string ConnectionString = Common.GetConnectionString();

                string rowsAffected = SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "spForgetPassword", parameters.ToArray()).ToString();
                return(rowsAffected);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 9
0
        public HttpResponseMessage forgotPassword(forgotPassword User)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Model State Invalid"));
            }
            try
            {
                using (Notestash_DatabaseEntities db = new Notestash_DatabaseEntities())
                {
                    var emailId = db.tblUsers.FirstOrDefault(e => e.Email == User.Email);
                    emailId.forgotPasswordCode = Guid.NewGuid();
                    db.SaveChanges();

                    changePasswordEmail(emailId.Email, emailId.forgotPasswordCode.ToString());
                    return(Request.CreateResponse(HttpStatusCode.OK, "Link to change password has been sent to your email id."));
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occurred, please try again!"));
            }
        }
Exemplo n.º 10
0
 public ActionResult Reset__password(forgotPassword oforgotPassword)
 {
     ViewBag.message = _IAccountServices.resetPasswordFromForget(oforgotPassword);
     return(View());
 }