public IActionResult Login(LoginViewModel model) { string us, pass, user; if (ModelState.IsValid) { EncDec enc = new EncDec(); pass = enc.HMACMD5Generator(model.Password); var result = _dbContext.User .Where(u => u.Password == pass && u.Username == model.UserName) .Select(x => x.UserID); if (result.Any()) { return(RedirectToAction("Index", "Customer", new { Area = "Customer" })); } else { ModelState.AddModelError("", "رمز یا نام کاربری نادرست"); } } return(View(model)); }
public ActionResult UpdateCustomerPass(string PrePass, string Pass) { EncDec enc = new EncDec(); tbl_Customer_Main tcm = new tbl_Customer_Main(); var coockie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCustomerCode()); if (coockie != null) { tcm = CoockieController.SayWhoIsHE(coockie.Value); var Id = tcm.id_Customer; PDBC db = new PDBC(); List <ExcParameters> parss = new List <ExcParameters>(); ExcParameters par = new ExcParameters() { _KEY = "@Id", _VALUE = Id }; parss.Add(par); par = new ExcParameters() { _KEY = "@PrePass", _VALUE = enc.HMACMD5Generator(PrePass) }; parss.Add(par); par = new ExcParameters() { _KEY = "@Pass", _VALUE = enc.HMACMD5Generator(Pass) }; parss.Add(par); db.Connect(); int Count = Convert.ToInt32(db.Select("SELECT COUNT(*) FROM [tbl_Customer_Main] WHERE id_Customer=@Id AND C_Password LIKE @PrePass", parss).Rows[0][0]); if (Count > 0) { string result = db.Script("UPDATE [tbl_Customer_Main] SET [C_Password]=@Pass WHERE [id_Customer]=@Id", parss); db.DC(); if (result == "1") { return(Content("Success")); } else { return(Content("ErrorSQL")); } } else { db.DC(); return(Content("pre_Pass")); } } else { return(Content("Error")); } }
public JsonResult LoginAuth(string mobile, string password) { var ModelSender = new ErrorReporterModel(); if (string.IsNullOrEmpty(mobile)) { ModelSender = new ErrorReporterModel { ErrorID = "EX1075463", Errormessage = $"لطفا شماره موبایل خودرا وارد نمایید", Errortype = "Error" }; return(Json(ModelSender)); } if (string.IsNullOrEmpty(password)) { ModelSender = new ErrorReporterModel { ErrorID = "EX1075463", Errormessage = $"لطفا کلمه عبور را وارد نمایید", Errortype = "Error" }; return(Json(ModelSender)); } EncDec dn = new EncDec(); password = dn.HMACMD5Generator(password); PDBC db = new PDBC(); List <ExcParameters> pars = new List <ExcParameters>(); ExcParameters par = new ExcParameters() { _KEY = "@Mobile", _VALUE = mobile }; pars.Add(par); par = new ExcParameters() { _KEY = "@PASS", _VALUE = password }; pars.Add(par); db.Connect(); DataTable dt = db.Select("SELECT [id_Customer] ,[C_Mobile] ,[C_FirstName] ,[C_LastNAme] FROM [tbl_Customer_Main] WHERE [C_Mobile] = @Mobile AND [C_Password] LIKE @PASS AND [C_ISActivate] = 1", pars); db.DC(); if (dt.Rows.Count == 1) { tbl_Customer_Main tcm = new tbl_Customer_Main() { id_Customer = dt.Rows[0]["id_Customer"].ToString(), C_FirstName = dt.Rows[0]["C_FirstName"].ToString(), C_LastNAme = dt.Rows[0]["C_LastNAme"].ToString(), C_Mobile = dt.Rows[0]["C_Mobile"].ToString() }; try { var userCookieIDV = new HttpCookie(ProjectProperies.AuthCustomerCode()); userCookieIDV.Value = CoockieController.SetCustomerAUTHCookie(tcm); userCookieIDV.Expires = DateTime.Now.AddDays(2); Response.SetCookie(userCookieIDV); } catch (Exception coockieEXception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth) { EXOBJ = coockieEXception }; ModelSender = new ErrorReporterModel { ErrorID = "EX1075463", Errormessage = $"عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید کد ارور شما {rep.CodeGenerated}", Errortype = "Error" }; return(Json(ModelSender)); } ModelSender = new ErrorReporterModel { ErrorID = "SX106", Errormessage = $"با موفقیت وارد شدید!", Errortype = "Success" }; return(Json(ModelSender)); } else { ModelSender = new ErrorReporterModel { ErrorID = "EX115", Errormessage = $"کاربری با این مشخصات یافت نشد!", Errortype = "Error" }; return(Json(ModelSender)); } }
public ActionResult ChangeAuthInformations(ChangeProfileModel informations) { changeAuthInformation information = informations.authInformation; if (ModelState.IsValid) { string adminID = ""; try { adminID = ((Administrator)Session["AdministratorRegistery"]).id_Admin; } catch (Exception exception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = exception }; } //If Session Doesent work try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); adminID = CoockieController.SayMyName(cookie.Value).id_Admin; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = EX }; } if (string.IsNullOrEmpty(adminID)) { adminID = "NO-ID"; } PDBC db = new PDBC(); List <ExcParameters> dbparams = new List <ExcParameters>(); ExcParameters param = new ExcParameters() { _VALUE = adminID, _KEY = "@id_Admin" }; dbparams.Add(param); db.Connect(); using (DataTable dt = db.Select("SELECT [ad_password] FROM [tbl_ADMIN_main] WHERE [id_Admin] = @id_Admin", dbparams)) { db.DC(); if (dt.Rows.Count > 0) { EncDec en = new EncDec(); string md5GeneratedPW = en.HMACMD5Generator(information.OLDpassword); if (md5GeneratedPW == dt.Rows[0]["ad_password"].ToString()) { if (string.IsNullOrEmpty(information.Newpassword1)) { param = new ExcParameters() { _VALUE = information.Username, _KEY = "@ad_username" }; dbparams.Add(param); db.Connect(); string result = db.Script("UPDATE [tbl_ADMIN_main] SET [ad_username] = @ad_username WHERE [id_Admin] = @id_Admin", dbparams); db.DC(); if (result == "1") { try { var sessionChanger = (Administrator)Session["AdministratorRegistery"]; sessionChanger.Username = information.Username; Session["AdministratorRegistery"] = sessionChanger; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 298)}") { EXOBJ = EX }; } try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); var sessionChanger = CoockieController.SayMyName(cookie.Value); sessionChanger.Username = information.Username; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(sessionChanger);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 315)}") { EXOBJ = EX }; } var ModelSender = new ErrorReporterModel { ErrorID = "SX102", Errormessage = "نام کاربری با موفقیت ویرایش شد!", Errortype = "Success" }; return(Json(ModelSender)); } else { PPBugReporter rep = new PPBugReporter(BugTypeFrom.SQL, result); var ModelSender = new ErrorReporterModel { ErrorID = "EX108", Errormessage = "عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید", Errortype = "Error" }; return(Json(ModelSender)); } } else { if (information.Newpassword1 == information.Newpassword2) { param = new ExcParameters() { _VALUE = information.Username, _KEY = "@ad_username" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = md5GeneratedPW, _KEY = "@ad_password" }; dbparams.Add(param); db.Connect(); string result = db.Script("UPDATE [tbl_ADMIN_main] SET [ad_password] = @ad_password,[ad_username] = @ad_username WHERE [id_Admin] = @id_Admin", dbparams); db.DC(); if (result == "1") { try { var sessionChanger = (Administrator)Session["AdministratorRegistery"]; sessionChanger.Username = information.Username; Session["AdministratorRegistery"] = sessionChanger; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); var sessionChanger = CoockieController.SayMyName(cookie.Value); sessionChanger.Username = information.Username; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(sessionChanger);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } var ModelSender = new ErrorReporterModel { ErrorID = "SX103", Errormessage = "اطلاعات ورود با موفقیت ویرایش شد!", Errortype = "Success" }; return(Json(ModelSender)); } else { PPBugReporter rep = new PPBugReporter(BugTypeFrom.SQL, result); var ModelSender = new ErrorReporterModel { ErrorID = "EX110", Errormessage = $"عدم توانایی در ویرایش اطلاعات با پشتیبانی تماس حاصل فرمایید! کد پیگیری برای شما :{rep.CodeGenerated}", Errortype = "Error" }; return(Json(ModelSender)); } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = "authInformation_Newpassword1", ErrorMessage = "عدم یکسانی کلمه های عبور" }; allErrors.Add(er); er = new ModelErrorReporter() { IdOfProperty = "authInformation_Newpassword2", ErrorMessage = "عدم یکسانی کلمه های عبور" }; allErrors.Add(er); var ModelSender = new ErrorReporterModel { ErrorID = "EX109", Errormessage = "عدم یکسانی کلمه های عبور", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = "authInformation_OLDpassword", ErrorMessage = "کلمه عبور بدرستی وارد نشده است" }; allErrors.Add(er); var ModelSender = new ErrorReporterModel { ErrorID = "EX105", Errormessage = $"کلمه عبور حال شما کلید شما برای ایجاد تغییرات میباشد", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX107", Errormessage = $"کاربر یافت نشد با پشتیبانی تماس بفرمایید", Errortype = "Error", }; return(Json(ModelSender)); } } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); var AllValues = ModelState.Values.ToList(); var AllKeys = ModelState.Keys.ToList(); int errorsCount = AllValues.Count; for (int i = 0; i < errorsCount; i++) { if (AllValues[i].Errors.Count > 0) { ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = AllKeys[i].Replace("authInformation.", "authInformation_"), ErrorMessage = AllValues[i].Errors[0].ErrorMessage }; allErrors.Add(er); } } var ModelSender = new ErrorReporterModel { ErrorID = "EX106", Errormessage = $"عدم رعایت استاندارد ها!", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } }
public ActionResult LoginAuth(LoginAuthForm adObj) { if (ModelState.IsValid) { EncDec dn = new EncDec(); adObj.Password = dn.HMACMD5Generator(adObj.Password); PDBC db = new PDBC(); List <ExcParameters> parasms = new List <ExcParameters>(); ExcParameters parameters = new ExcParameters() { _KEY = "@username", _VALUE = adObj.Username }; parasms.Add(parameters); parameters = new ExcParameters() { _KEY = "@password", _VALUE = adObj.Password }; parasms.Add(parameters); db.Connect(); using (DataTable dt = db.Select("SELECT * FROM [tbl_ADMIN_main] WHERE ad_username LIKE @username AND ad_password LIKE @password", parasms)) { db.DC(); int dtrowcount = dt.Rows.Count; if (dtrowcount > 0) { if (dt.Rows[0]["ad_isActive"].ToString() == "1") { Administrator AdminSession = new Administrator() { id_Admin = dt.Rows[0]["id_Admin"].ToString() , ad_typeID = dt.Rows[0]["ad_typeID"].ToString() , ad_firstname = dt.Rows[0]["ad_firstname"].ToString() , ad_lastname = dt.Rows[0]["ad_lastname"].ToString() , ad_avatarprofile = dt.Rows[0]["ad_avatarprofile"].ToString() , ad_email = dt.Rows[0]["ad_email"].ToString() , ad_phone = dt.Rows[0]["ad_phone"].ToString() , ad_mobile = dt.Rows[0]["ad_mobile"].ToString() , ad_has2stepSecurity = dt.Rows[0]["ad_has2stepSecurity"].ToString() , ad_isActive = dt.Rows[0]["ad_isActive"].ToString() , ad_isDelete = dt.Rows[0]["ad_isDelete"].ToString() , ad_lastseen = dt.Rows[0]["ad_lastseen"].ToString() , ad_lastlogin = dt.Rows[0]["ad_lastlogin"].ToString() , ad_loginIP = dt.Rows[0]["ad_loginIP"].ToString() , ad_regdate = dt.Rows[0]["ad_regdate"].ToString() , ad_personalColorHexa = dt.Rows[0]["ad_personalColorHexa"].ToString() , AdminModeID = dt.Rows[0]["AdminModeID"].ToString() , ad_NickName = dt.Rows[0]["ad_NickName"].ToString(), Username = adObj.Username }; try { Session["AdministratorRegistery"] = AdminSession; try { var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(AdminSession);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception coockieEXception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth) { EXOBJ = coockieEXception }; var ModelSender = new ErrorReporterModel { ErrorID = "EX103", Errormessage = $"عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید کد ارور شما {rep.CodeGenerated}", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } if (string.IsNullOrEmpty(adObj.urlRedirection)) { return(RedirectToAction("Logs", "AdminLoginAuth")); } else { string[] GotToPage = adObj.urlRedirection.Split('-'); string actionname = ""; string controllername = ""; for (int i = 0; i < 2; i++) { if (GotToPage[i].Contains("A_")) { actionname = GotToPage[i].Replace("A_", ""); } else { controllername = GotToPage[i]; } } return(RedirectToAction(actionname, controllername)); } } catch (Exception SessionException) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth) { EXOBJ = SessionException }; var ModelSender = new ErrorReporterModel { ErrorID = "EX103", Errormessage = $"عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید کد ارور شما {rep.CodeGenerated}", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX101", Errormessage = "کاربر پیدا شده در وضعیت غیر فعال میباشد و اجازه دسترسی به پنل را نخواهد داشت", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX102", Errormessage = "کاربری با این مشخصات یافت نشد!", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } db.DC(); return(View("Index")); } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX100", Errormessage = "درخواست ارسال شده مطابق با ساختار امنیتی نمیباشد", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } }