public ActionResult Create(string username, string password, string name, string MiddleName, string surname, string PersonalID, string PhoneNumber, string email, System.DateTime DateOfAppointment, bool active, bool Administrator) { using (Context _context = new Context()){ User newUser = new User(); newUser.Id = System.Guid.NewGuid(); newUser.Username = username; newUser.Password = Password_Hasher.Hash(password); newUser.Name = name; newUser.MiddleName = MiddleName; newUser.SurName = surname; newUser.PersonalID = PersonalID; newUser.PhoneNumber = PhoneNumber; newUser.Email = email; newUser.DateOfAppointment = DateOfAppointment; newUser.Active = active; newUser.Administrator = Administrator; _context.Users.Add(newUser); _context.SaveChanges(); dynamic mymodel = new System.Dynamic.ExpandoObject(); mymodel.LoggedUser = SharedData.logged; mymodel.Users = _context.Users.ToList(); return(View("~/Views/Platform/Users.cshtml", mymodel)); } }
/// <summary> /// Requests a log in for the user. /// </summary> private bool LogIn() { Console.Write("Username: "******"Password: "); string password = Console.ReadLine(); if (Password_Hasher.Verify(password, UserBusiness.GetUser(UserBusiness.GetID(username)).Password)) { return(true); } return(false); }
/// <summary> /// Requests a register of a new user. /// </summary> private void Register() { Console.Write("Username: "******"Password: "); string password = Console.ReadLine(); string hashed_pass = Password_Hasher.Hash(password); if (!Password_Hasher.Verify(password, hashed_pass)) { return; } UserBusiness.Register(username, hashed_pass); }
public ActionResult Verify(string username, string password) { using (Context _context = new Context()){ User result = _context.Users.ToList().Find(x => x.Username == username); if (!Password_Hasher.Verify(password, result.Password) || !result.Active) { //TODO: Create Exception return(View("~/Views/Home/Index.cshtml")); } SharedData.logged = result; return(View("Home")); } }
public static void CreateAdmin() { using (Context _context = new Context()){ User FirstAdmin = new User(); FirstAdmin.Id = Guid.NewGuid(); FirstAdmin.Username = "******"; FirstAdmin.Password = Password_Hasher.Hash("adminpass"); FirstAdmin.Name = "Hristo"; FirstAdmin.MiddleName = "Antonov"; FirstAdmin.SurName = "Kanev"; FirstAdmin.PersonalID = "4568432687"; FirstAdmin.PhoneNumber = "0878987668"; FirstAdmin.Email = "*****@*****.**"; FirstAdmin.DateOfAppointment = DateTime.Now; FirstAdmin.Active = true; FirstAdmin.Administrator = true; _context.Users.Add(FirstAdmin); _context.SaveChanges(); } }
/// <summary> /// Requests a user to be removed. /// </summary> private void RemoveUser() { Console.Clear(); Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 14) + "USER REMOVAL"); Console.WriteLine(new string('-', 40) + '\n'); for (int i = 0; i < 4; i++) { Console.Write("Password: "******"The password you have entered is incorrect\nTry again! {i + 1}/4\n"); } }