コード例 #1
0
 public AppUser FindByName(string appUserName)
 {
     try
     {
         AppUserRepository repository    = new AppUserRepository(context);
         AppUser           objectAppUser = repository.FindByName(appUserName);
         return(objectAppUser);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #2
0
        public string Authenticated(AppUser login)
        {
            try
            {
                AppUserRepository appUserRepository = new AppUserRepository(context);
                AppUser           findAppUser       = appUserRepository.FindByName(login.Name);

                if (findAppUser != null)
                {
                    //if (login.Name != "TouresBalon")
                    //{

                    //        //if (findAppUser.Active)
                    //        //{
                    //            string path = "LDAP://DC=" + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectory"] + ",DC=" + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectoryExtension"];
                    //            string filterAttribute = "";

                    //            string domainAndUsername = System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectory"] + "." + System.Configuration.ConfigurationManager.AppSettings["domainActiveDirectoryExtension"] + @"\" + login.Name;
                    //            DirectoryEntry entry = new DirectoryEntry(path, domainAndUsername, login.Password);

                    //            try
                    //            {
                    //                object obj = entry.NativeObject;
                    //                DirectorySearcher search = new DirectorySearcher(entry);
                    //                search.Filter = "(SAMAccountName=" + login.Name + ")";
                    //                search.PropertiesToLoad.Add("cn");
                    //                SearchResult result = search.FindOne();

                    //                if (null == result)
                    //                {
                    //                    return LoginStatus.WRONG_PASSWORD;
                    //                }
                    //                path = result.Path;
                    //                filterAttribute = (String)result.Properties["cn"][0];
                    //            }
                    //            catch (Exception ex)
                    //            {
                    //                return LoginStatus.WRONG_PASSWORD;
                    //            }
                    //            return LoginStatus.OK;
                    //        //}
                    //        //else
                    //        //{
                    //        //    return LoginStatus.USER_INACTIVE;
                    //        //}

                    //}
                    //else
                    //{

                    EncryptionFactory  factory   = new EncryptionFactory();
                    IEncryptionFactory encriptor = factory.GetProvider(EncryptionProvider.TripeDes);
                    encriptor.Key = ConfigurationManager.AppSettings["encriptorKey"];
                    encriptor.IV  = ConfigurationManager.AppSettings["encriptorIV"];
                    string encriptPassword = encriptor.Encrypt(login.Password);
                    if (encriptPassword == findAppUser.Password)
                    {
                        return(LoginStatus.OK);
                    }
                    else
                    {
                        return(LoginStatus.WRONG_PASSWORD);
                    }
                    //}
                }
                else
                {
                    return(LoginStatus.APPUSER_NOT_FOUND);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                throw;
            }
        }