public ActionResult Login(VmLogin login) { if (ModelState.IsValid) { Models.Admins admin = db.Admins.FirstOrDefault(a => a.Username == login.Username); if (admin != null) { if (Crypto.VerifyHashedPassword(admin.Password, login.Password) == true) { Session["Loginner"] = admin; Session["LoginnerId"] = admin.Id; return(RedirectToAction("Dashboard")); } else { ModelState.AddModelError("Password", "Wronge"); } } else { ModelState.AddModelError("Username", "Wronge"); } } return(View()); }
public IActionResult OnGet(int?id) { string DbConnection = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\disko\OneDrive\1. Sheffiled Hallam University\Databases and Web\web\Assignment\Group\Group_Project_Assignment\Databases\Database.mdf;Integrated Security=True"; SqlConnection conn = new SqlConnection(DbConnection); conn.Open(); AdminRecords = new Models.Admins(); using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandText = "SELECT * FROM Admin WHERE AdminId = @AdminID"; command.Parameters.AddWithValue("@AdminID", id); Console.WriteLine("The id : " + id); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { AdminRecords.AdminID = reader.GetInt32(0); AdminRecords.AdminUserName = reader.GetString(1); AdminRecords.AdminEmail = reader.GetString(2); AdminRecords.AdminPassword = reader.GetString(3); } } conn.Close(); return(Page()); }
public ActionResult Run() { string username = Request.Form["usx"]; string password = SecurityPassword.CreateMD5Hash(Request.Form["passx"]); string guid = Request.Form["guid"]; if (guid == viewModel.CRN) { using (b3752Entities db = new b3752Entities()) { db.Configuration.ProxyCreationEnabled = false; Guid ID = (from admins in db.Admins where admins.Username == username select admins.ID).Single(); Models.Admins admin = (from admins in db.Admins where admins.ID == ID && admins.Password == password select admins).Single(); if (admin == null) { return(Redirect("/Admin/LogIn")); } else { Session["AdminID"] = admin.ID; return(Redirect("/Admin/Dashboard")); } } } else { return(Redirect("/Admin/LogIn")); } }
public void OnGet() { string DbConnection = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\disko\OneDrive\1. Sheffiled Hallam University\Databases and Web\web\Assignment\Group\Group_Project_Assignment\Databases\Database.mdf;Integrated Security=True"; SqlConnection conn = new SqlConnection(DbConnection); conn.Open(); using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandText = @"SELECT * FROM Admin"; SqlDataReader reader = command.ExecuteReader(); AdminRecord = new List <Models.Admins>(); while (reader.Read()) { Models.Admins record = new Models.Admins(); record.AdminID = reader.GetInt32(0); record.AdminUserName = reader.GetString(1); record.AdminEmail = reader.GetString(2); record.AdminPassword = reader.GetString(3); AdminRecord.Add(record); } reader.Close(); } using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandText = @"SELECT * FROM Userz"; SqlDataReader reader = command.ExecuteReader(); UserRecord = new List <Models.Users>(); while (reader.Read()) { Models.Users record = new Models.Users(); record.MemberID = reader.GetInt32(0); record.UserName = reader.GetString(1); record.UserEmail = reader.GetString(2); record.UserCard = reader.GetString(3); record.UserPassword = reader.GetString(4); UserRecord.Add(record); } reader.Close(); } }
public string AddAdmin([FromBody] Models.Admins admins) { var status = "Adding admin Failed"; try { status = _AdminFacade.Create(admins.Email, con.Encrypt(admins.Pass), admins.Pno); } catch (Exception e) { status = e.Message; throw e; } return(status); }
public string AuthAdmin([FromBody] Models.Admins admins) { var status = "Login failed"; try { if (admins.Email == "") { admins.Email = admins.Pno; } status = _AdminFacade.Auth(admins.Email, con.Encrypt(admins.Pass)); } catch (Exception e) { Console.WriteLine(e.Message); status = "Login Failed"; throw e; } return(status); }
public ActionResult Index() { if (Session["AdminID"] != null) { using (b3752Entities db = new b3752Entities()) { Models.Admins admin = db.Admins.Find(Guid.Parse(Session["AdminID"].ToString())); if (admin != null) { return(View()); } else { return(Redirect("/Admin/LogIn")); } } } else { return(Redirect("/Admin/LogIn")); } }