public ActionResult Login(UserDetail userdetails) { string EncryptedPassword, UserPassword; UserPassword = userdetails.Password; EncryptedPassword = PasswordSecurity.EncryptPassword(UserPassword); var user = db.UserDetails.Where(x => x.Email == userdetails.Email && x.Password == EncryptedPassword).FirstOrDefault(); if (user == null) { ModelState.AddModelError("", "Invalid Username and Password"); } else { Session["username"] = user.FirstName; Session["userid"] = user.UserId; Session["mobile"] = user.Contact; Session["address"] = user.Address; Session["email"] = user.Email; System.Diagnostics.Debug.WriteLine(Session["username"] + " " + Session["userid"] + " " + Session["mobile"]); return(RedirectToAction("ListProduct", "Home")); } return(View()); }
public ActionResult Registration(UserDetail userdetails) { if (ModelState.IsValid) { string password, EncryptedPassword; password = userdetails.Password; EncryptedPassword = PasswordSecurity.EncryptPassword(password); userdetails.Password = EncryptedPassword; db.UserDetails.Add(userdetails); if (db.SaveChanges() > 0) { string receiver = userdetails.Email; string subject = "Registrating"; string message = "You are registered in Vehicle Leasing now you can login"; if (MailSending.SendMail(receiver, subject, message)) { return(RedirectToAction("Login")); } return(View(userdetails)); } } return(View(userdetails)); }
public ActionResult ResetUserPassword(String Email, String Password) { if (Email == "") { TempData["Msg"] = "Email not Exists!"; } else { UserDetail user = new UserDetail(); user.Password = Password; var EncryptedPassword = PasswordSecurity.EncryptPassword(user.Password); var result = UpdatePassword(Email, EncryptedPassword); if (result != false) //HttpResponseMessage Res = await GlobalVariables.client.GetAsync("Users/UpdateUserPassword?Email=" + Email + "&Password="******"Message"] = "Password Successfully Reset."; return(View()); } } return(View()); }
public async Task <ActionResult> Login(Account model, string returnUrl) { _EmployeesManager = new commonEmployeesEntities(); learUser = new gatepassEntities(); _AccountManager = new lear_DailiesCertificationRequirementEntities(); PasswordSecurity ps = new PasswordSecurity(); System.Diagnostics.Debug.WriteLine(ps.EncryptPassword(model.Password) + " : pass"); var adminPass = ps.EncryptPassword(model.Password); var adminAccount = _AccountManager.Users.Where(us => us.BadgeNo.ToString().Equals(model.BagdeNo) && us.Password.Equals(adminPass)).FirstOrDefault(); //System.Diagnostics.Debug.WriteLine(adminAccount.Password+" : password"); if (!ModelState.IsValid) { return(View(model)); } Account user = new Account() { BagdeNo = model.BagdeNo, Roles = "", Password = model.Password }; user = Repository.GetAccountDetails(user); // Calling getAccountDetailsFunction from Repository Class // check if User is exist.. if (user != null) { // if true.. // Get Employee Details Employees_Details userrr = _EmployeesManager.Employees_Details.Where(em => em.Employee_ID == user.BagdeNo).FirstOrDefault(); var intBadge = System.Int32.Parse(model.BagdeNo).ToString(); // Get User info from user_vw using BadgeNo users_vw usertemp = learUser.users_vw.Where(use => use.Employee_ID == user.BagdeNo).FirstOrDefault(); // Get total Number of Employees var countEmployees = _EmployeesManager.Employees_Details.ToList(); // Get total Number of Active Employees var countActiveEmployees = _EmployeesManager.Employees_Details.Where(emp => emp.Job_Status.ToUpper().Contains("CURRENT")).ToList().Count(); // Get total Number of Newly Employed Employees var countNewlyEmployees = _EmployeesManager.newlyEmployees.Where(emp => emp.Payroll_Type.ToString().ToUpper().Equals("DAILY")).OrderBy(nwEmp => nwEmp.Last_Name).ToList(); // Set Authentication Cookie to User's EMAIL ADDRESS FormsAuthentication.SetAuthCookie(usertemp.Email, false); // [ BEGIN -- Authentication Configuration var authTicket = new FormsAuthenticationTicket(1, usertemp.Email, DateTime.Now, DateTime.Now.AddMinutes(720), false, user.Roles); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); // -- END Authentication Configuration ] // [ BEGIN -- Session Configuration Session["User"] = usertemp.Email; Session["RoleUser"] = user.Roles; Session["UserId"] = user.BagdeNo; Session["NumberOfEmployees"] = countEmployees.Count(); Session["NumberOfUnderEmployees"] = _EmployeesManager.Emp_Route.Where(emp => emp.Checker_1_ID == user.BagdeNo).ToList().Count(); Session["NumberOfNewlyEmployees"] = countNewlyEmployees.Count(); Session["NumberOfActiveEmployees"] = countActiveEmployees; Session["NumberOfInactiveEmployees"] = countEmployees.Count() - countActiveEmployees; if (userrr != null) { Session["UserPosition"] = userrr.Position; } // -- END Session Configuration ] return(RedirectToAction("Home", "Home")); } else if (/*model.BagdeNo.ToString() == "1234" && model.Password.ToString() =="IT"*/ adminAccount != null) // Hardcoded User For IT admin { // Get total Number of Dailies Employees var countEmployees = _EmployeesManager.Employees_Details.Where(emp => emp.Payroll_Type.ToUpper().Equals("DAILY")).ToList(); // Get total Number of Active Employees var countActiveEmployees = _EmployeesManager.Employees_Details.Where(emp => emp.Job_Status.ToUpper().Contains("CURRENT") && emp.Payroll_Type.ToUpper().Equals("DAILY")).ToList().Count(); // Get total Number of Newly Employed Employees var countNewlyEmployees = _EmployeesManager.newlyEmployees.Where(emp => emp.Payroll_Type.ToString().ToUpper().Equals("DAILY")).OrderBy(nwEmp => nwEmp.Last_Name).ToList(); // Get total Number of Probationary Employees var countProbationaryEmployees = _AccountManager.EmployeeDCR_Vw.Where(emp => emp.EmploymentStatus.ToUpper().Equals("PROBATIONARY") && emp.Job_Status.ToUpper().Contains("CURRENT") && emp.PayrollType.ToUpper().Equals("DAILY")).ToList().Count(); // Set Authentication Cookie to User's EMAIL ADDRESS -- ( Hardcoded ) FormsAuthentication.SetAuthCookie("*****@*****.**", false); // [ BEGIN -- Authentication Configuration var authTicket = new FormsAuthenticationTicket(1, "*****@*****.**", DateTime.Now, DateTime.Now.AddMinutes(720), true, "IT"); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); // -- END Authentication Configuration ] // [ BEGIN -- Session Configuration Session["User"] = "******"; Session["RoleUser"] = "******"; Session["UserId"] = "IT"; Session["UserPosition"] = "ITAdmin"; Session["NumberOfEmployees"] = countEmployees.Count(); Session["NumberOfNewlyEmployees"] = countNewlyEmployees.Count(); Session["NumberOfActiveEmployees"] = countActiveEmployees; Session["NumberOfInactiveEmployees"] = countEmployees.Count() - countActiveEmployees; Session["NumberOfRecertificationPlans"] = _AccountManager.ReCertificationPlans.ToList().Count(); Session["NumberOfCertificates"] = _AccountManager.Certifications.ToList().Count(); Session["NumberOfProbationaryEmployees"] = countProbationaryEmployees; // [ BEGIN -- Session Configuration return(RedirectToAction("Home", "Home")); } else // else return View with error mesage. { ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public static Account GetAccountDetails(Account account) { var intBagde = System.Int32.Parse(account.BagdeNo); System.Diagnostics.Debug.WriteLine(intBagde); //Console Display For Debug Purposes // get User from user_vw with Default Password (Lear) //var accc = leardbUser.user_vw.Where(u => u.badge_no.ToLower() == intBagde.ToString().ToLower() && u.password == account.Password).FirstOrDefault(); //System.Diagnostics.Debug.WriteLine(accc); //Console Display For Debug Purposes // get User from users_vw // Comment next Line For Deploying // Uncomment for Testing-- var accc = leardbUser.users_vw.Where(u => u.Employee_ID.ToLower() == account.BagdeNo.ToString().ToLower() && "Lear" == account.Password).FirstOrDefault(); // encrypt Password var passEn = passSecure.EncryptPassword(account.Password); // get User from user_vw with their Own Password: //var accc1 = leardbUser.user_vw.Where(u => u.badge_no.ToLower() == intBagde.ToString().ToLower() && u.Employee_Password == passEn).FirstOrDefault(); // get User from users_vw var accc1 = leardbUser.users_vw.Where(u => u.Employee_ID.ToLower() == account.BagdeNo.ToString().ToLower() && u.Employee_Password == passEn).FirstOrDefault(); System.Diagnostics.Debug.WriteLine(accc1);//Console Display For Debug Purposes // Check if User with Default Password is exist if (accc != null) { // if exist--- // Get all approvers from Database var users = learEmployees.Database.SqlQuery <Approver>("Select * from approvers").ToList <Approver>(); // Set variable Roles as 'Default' var Roles = "Default"; // Check if Default User is an Approver VIA foreach loop foreach (Approver app in users) { if (accc.Employee_ID.Equals(app.approver.ToString().ToLower())) { // if User is consider as Approver set variable Roles to 'Approver' Roles = "Approver"; break; } } // Initialize account and set its attributes by the Defaut User Account acc = new Account() { BagdeNo = account.BagdeNo, Roles = Roles, Password = accc.Employee_Password }; return(acc); } else if (accc1 != null) // else if Default User not exist check User with its prefer password { // if exist--- // Get all approvers from Database var users = learEmployees.Database.SqlQuery <Approver>("Select * from approvers").ToList <Approver>(); // Set variable Roles as 'Default' var Roles = "Default"; // Check if Default User is an Approver VIA foreach loop foreach (Approver app in users) { if (accc1.Employee_ID.Equals(app.approver.ToString().ToLower())) { // if User is consider as Approver set variable Roles to 'Approver' Roles = "Approver"; break; } } // Initialize account and set its attributes by the Defaut User Account acc = new Account() { BagdeNo = account.BagdeNo, Roles = Roles, Password = accc1.Employee_Password }; return(acc); } else // else just return null { return(null); } }