public int userLogin(User user) { int loginState = 0; byte[] userPassword = new SHA1Managed().ComputeHash( ASCIIEncoding.ASCII.GetBytes(user.UserPassword)); // manager.CreateUser(user.UserLoginID,userPassword); try { // if(manager.UserExists(user.UserLoginID)) // { // if(Convert.ToBase64String(userPassword).Equals // (Convert.ToBase64String(manager.GetPassword(user.UserLoginID)))) // { NamePasswordCredential credentials; credentials = new NamePasswordCredential(user.UserLoginID, ASCIIEncoding.ASCII.GetBytes(user.UserPassword)); IAuthenticationProvider authProvider; authProvider = AuthenticationFactory.GetAuthenticationProvider("Database Provider"); bool authenticated = false; IIdentity identity; authenticated = authProvider.Authenticate(credentials, out identity); if (authenticated) { loginState = 1; //登陆成功 IRolesProvider rolesProvider = RolesFactory.GetRolesProvider("Role Database Provider"); IPrincipal principal = rolesProvider.GetRoles(identity); Thread.CurrentPrincipal = principal; } // } // else // { // loginState = 2;//密码错误 // } // } // else // { // loginState = -1;//用户不存在 // } } catch (Exception ex) { throw ex; } return(loginState); }
public void CheckThatRoleProviderFactoryCreatesValidADRoleProviderInstance() { adRolesProvider = null; Assert.IsNull(adRolesProvider); adRolesProvider = (AdRolesProvider)RolesFactory.GetRolesProvider("AdRolesProviderName", context); Assert.IsNotNull(adRolesProvider); Assert.AreEqual("Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.AdRolesProvider", adRolesProvider.ToString()); }
public void CheckThatRoleProviderFactoryCreatesValidDBRoleProviderInstance() { dbRolesProvider = null; Assert.IsNull(dbRolesProvider); dbRolesProvider = (DbRolesProvider)RolesFactory.GetRolesProvider("DbRolesProviderName"); Assert.IsNotNull(dbRolesProvider); Assert.AreEqual("Microsoft.Practices.EnterpriseLibrary.Security.Database.DbRolesProvider", dbRolesProvider.ToString()); }
public void CheckThatRoleProviderFactoryDoesNotReturnInvalidDBRoleProviderInstance() { DbRolesProvider tmpDbRolesProvider = (DbRolesProvider)RolesFactory.GetRolesProvider("NonConfiguredDbRolesProviderName"); Assert.Fail(); }
public void Setup() { dbRolesProvider = (DbRolesProvider)RolesFactory.GetRolesProvider("DbRolesProviderName"); }
public void CheckThatRoleProviderFactoryDoesNotReturnInvalidAdRoleProviderInstance() { RolesFactory.GetRolesProvider("NonConfiguredAdRolesProviderName", context); }
public void SetUp() { adRolesProvider = (AdRolesProvider)RolesFactory.GetRolesProvider("AdRolesProviderName", context); }