/// <summary> /// 根据用户名和口令对用户进行认证。 /// </summary> /// <param name="username">用户名</param> /// <param name="password">口令</param> /// <returns>用户通过认证,则返回true;否则返回false。</returns> bool IAuthenticator.Authenticate(string username, string password) { bool authenticated = false; Tutor tutor = _tutorMgr.GetByName(username); if (tutor != null && tutor.Authenticate(password)) { authenticated = true; IIdentity identity = new GenericIdentity(username); List <string> roles = new List <string>(); if (tutor.IsManager) { roles.Add("Administrator"); } IPrincipal principal = new GenericPrincipal(identity, roles.ToArray()); Thread.CurrentPrincipal = principal; } //将验证结果返回 return(authenticated); }