예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        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());
        }
예제 #4
0
        public void CheckThatRoleProviderFactoryDoesNotReturnInvalidDBRoleProviderInstance()
        {
            DbRolesProvider tmpDbRolesProvider = (DbRolesProvider)RolesFactory.GetRolesProvider("NonConfiguredDbRolesProviderName");

            Assert.Fail();
        }
예제 #5
0
 public void Setup()
 {
     dbRolesProvider = (DbRolesProvider)RolesFactory.GetRolesProvider("DbRolesProviderName");
 }
예제 #6
0
 public void CheckThatRoleProviderFactoryDoesNotReturnInvalidAdRoleProviderInstance()
 {
     RolesFactory.GetRolesProvider("NonConfiguredAdRolesProviderName", context);
 }
예제 #7
0
 public void SetUp()
 {
     adRolesProvider = (AdRolesProvider)RolesFactory.GetRolesProvider("AdRolesProviderName", context);
 }