public void Login(string userName, string password) { if (userName == null || password == null) { throw new ArgumentNullException(); } //Get the User DataTable userTable = _dbLib.UserGet(null, userName); if (userTable == null || userTable.Rows.Count != 1) { throw new SecurityException("Invalid UserName or Password"); } DataRow dataRow = userTable.Rows[0]; if (((string)dataRow["UserName"]).ToLower(CultureInfo.CurrentCulture) != userName.ToLower(CultureInfo.CurrentCulture) || (string)dataRow["Password"] != password) { throw new SecurityException("Invalid UserName or Password"); } _isValid = true; _loginTime = _lastAccessedTime = DateTime.Now; // Set the Custom Principal object User user = new User(this, dataRow); _principal = new EAPrincipal(new List <string>(new string[] { user.Role.ToString() }), user); Thread.CurrentPrincipal = _principal; }
public void Logout() { _isValid = false; _application = null; _principal = null; using (TransactionScope scope = new TransactionScope()) { _dbLib.SessionDelete(_id, DateTime.Now); scope.Complete(); } }
internal void Login(string userName) { User[] users = this.Find(new UserSearchCriteria(null)); User currentUser = null; foreach (User user in users) { if (user.Name == userName) { currentUser = user; break; } } _isValid = true; _loginTime = _lastAccessedTime = DateTime.Now; //initialize the Custom Principal object _principal = new EAPrincipal(new List <string>(new string[] { currentUser.Role.ToString() }), currentUser); Thread.CurrentPrincipal = _principal; }