public int EditUser(User u) { if (_users.GetUserById(u.UserId) != null) { AesEncrpyt en = new AesEncrpyt(); u.Username = en.Encrypt(u.Username); u.Password = en.Encrypt(u.Password); return(_users.UpdateUser(u)); } return(0); }
public User Login(String username, String password) { AesEncrpyt en = new AesEncrpyt(); User u = _users.GetUserByUNPW(en.Encrypt(username), en.Encrypt(password)); if (u != null && !u.Lock) { u.Username = username;//en.Decrypt(u.Username); return(u); } return(null); }
public int ChangePassword(ChangePassword cp, User u) { AesEncrpyt en = new AesEncrpyt(); User user = _users.GetUserByUNPW(u.Username, en.Encrypt(cp.OldPassword)); if (user != null) { user.Password = en.Encrypt(cp.NewPassword); _users.UpdateUser(user); _users.Save(); return(1); } return(0); }
public ActionResult ChangePassword(ChangePassword cp) { if (ModelState.IsValid) { using (UserAccountService _uas = new UserAccountService()) { int code = 0; User user = _uas.GetUser(Convert.ToInt32(Session["Id"])); AesEncrpyt en = new AesEncrpyt(); if (user.Password.Equals(en.Encrypt(cp.OldPassword))) { code = _uas.ChangePassword(cp, user); if (code == 1) { ViewBag.ChangePasswordMessage = "Successfuly changed password!"; } else { ViewBag.ChangePasswordMessage = "Password change unsuccessful."; } } else { ViewBag.ChangePasswordMessage = "Password change unsuccessful."; } } } return(View()); }
public User Register(User u) { AesEncrpyt en = new AesEncrpyt(); u.Username = en.Encrypt(u.Username); u.Password = en.Encrypt(u.Password); if (_users.GetUserByUNPW(u.Username, u.Password) == null) { _users.InsertUser(u); _users.Save(); return(u); } return(null); }
public int UpdateUserPW(User u) { if (_users.GetUserById(u.UserId) != null) { AesEncrpyt en = new AesEncrpyt(); u.Password = en.Encrypt(u.Password); return(_users.UpdateUser(u)); } else { return(0); } }
public int RegisterClient(ClientUser client) { Client c = new Client(); c.FirstName = client.FirstName; c.LastName = client.LastName; c.PhoneNumber = client.PhoneNumber; c.Email = client.Email; c.Username = client.Username; c.Password = client.Password; c.CompanyName = client.CompanyName; c.CompanyAddress = client.CompanyAddress; c.CompanyDescription = client.CompanyDesc; c.Type = AccountType.Client; AesEncrpyt en = new AesEncrpyt(); c.Username = en.Encrypt(client.Username); c.Password = en.Encrypt(client.Password); if (!_users.isExistingUsername(c.Username)) { if (!_users.isExistingEmail(c.Email)) { _users.InsertUser(c); _users.Save(); return(99); } return(2); } else { return(1); } }
public ActionResult ResetPassword(ResetPassword rp) { if (ModelState.IsValid) { AesEncrpyt en = new AesEncrpyt(); using (UserAccountService uas = new UserAccountService()) { User user = uas.GetUserByEmail(rp.Email); user = uas.GetUserByUnPW(user.Username, en.Encrypt(rp.TempPassword)); if (user != null) { user.Password = rp.NewPassword; uas.UpdateUserPW(user); } } return(RedirectToAction("Login", "Account")); } return(View()); }
public int RegisterStudent(StudentUser stUser) { Student s = new Student(); s.FirstName = stUser.FirstName; s.LastName = stUser.LastName; s.PhoneNumber = stUser.PhoneNumber; s.Email = stUser.Email; s.Username = stUser.Username; s.Password = stUser.Password; s.StudentNumber = Convert.ToInt32(stUser.StudentNumber); s.ProgramId = stUser.ProgramId; s.Type = AccountType.Student; s.Lock = false; AesEncrpyt en = new AesEncrpyt(); s.Username = en.Encrypt(stUser.Username); s.Password = en.Encrypt(stUser.Password); //Admin u = new Admin(); //u.FirstName = "Super"; //u.LastName = "Admin"; //u.PhoneNumber = "9998887777"; //u.Email = "*****@*****.**"; //u.Username = "******"; //u.Password = "******"; //u.Username = en.Encrypt(u.Username); //u.Password = en.Encrypt(u.Password); //u.Type = AccountType.Admin; //u.Lock = false; //1 - username already exist //2 = studentnumber already exist //3 = existing email //99 - success if (!_users.isExistingEmail(s.Email)) { if (!_users.isExistingUsername(s.Username)) { using (StudentRepository sr = new StudentRepository()) { if (!sr.isExistingStudentNumber(s.StudentNumber)) { _users.InsertUser(s); //_users.InsertUser(u); _users.Save(); return(99); } else { return(2); } } } else { return(1); } } else { return(3); } }
public int CreateUser(CreateAccount ac) { AesEncrpyt en = new AesEncrpyt(); ac.Username = en.Encrypt(ac.Username); ac.Password = en.Encrypt(ac.Password); if (_users.isExistingUsername(ac.Username)) { return(4); } if (_users.isExistingEmail(ac.Email)) { return(5); } if (ac.SelectedAccount.Equals(AccountType.Coop_Advisor)) { Coop_Advisor ca = new Coop_Advisor(); ca.FirstName = ac.FirstName; ca.LastName = ac.LastName; ca.Username = ac.Username; ca.Password = ac.Password; ca.PhoneNumber = ac.PhoneNumber; ca.Email = ac.Email; ca.Type = AccountType.Coop_Advisor; ca.Lock = false; _users.InsertUser(ca); _users.Save(); return(1); } else if (ac.SelectedAccount.Equals(AccountType.Management)) { Management ma = new Management(); ma.FirstName = ac.FirstName; ma.LastName = ac.LastName; ma.Username = ac.Username; ma.Password = ac.Password; ma.PhoneNumber = ac.PhoneNumber; ma.Email = ac.Email; ma.Type = AccountType.Management; ma.Lock = false; _users.InsertUser(ma); _users.Save(); return(2); } else if (ac.SelectedAccount.Equals(AccountType.Admin)) { Admin ad = new Admin(); ad.FirstName = ac.FirstName; ad.LastName = ac.LastName; ad.Username = ac.Username; ad.Password = ac.Password; ad.PhoneNumber = ac.PhoneNumber; ad.Email = ac.Email; ad.Type = AccountType.Admin; ad.Lock = false; _users.InsertUser(ad); _users.Save(); return(3); } else { return(0); } }