private static void AddCredential(RequestCredential rc) { lock (vetex) { if (credentials == null) { credentials = new Dictionary <string, RequestCredential>(); } if (credentials.ContainsKey(rc.Token)) { return; } credentials.Add(rc.Token, rc); } }
public GeneralResponse <RequestCredential> Login(RequestCredential rc) { if (!String.IsNullOrEmpty(rc.Domain)) { if (ADLogin(rc.UserName, rc.Domain, rc.Password)) { rc.Token = Guid.NewGuid().ToString(); AddCredential(rc); return(new GeneralResponse <RequestCredential>(rc)); } else { return(new GeneralResponse <RequestCredential>(2, "Can not login with AD user.")); } } rc.Token = Guid.NewGuid().ToString(); AddCredential(rc); return(new GeneralResponse <RequestCredential>(rc)); }
public override void Validate(string userName, string password) { RequestCredential rc = new RequestCredential() { UserName = userName, Password = password, Domain = "mhs" }; GeneralResponse <RequestCredential> loginResult = new LoginServiceHanlder().Login(rc); if (!loginResult.IsSuccess()) { FaultException fault = new FaultException( new FaultReason("UserName or password is wrong!"), new FaultCode("Error:0x0001")); throw fault; } }
/// <summary> /// Domain Account Login /// </summary> /// <param name="rc"></param> /// <returns></returns> public GeneralResponse <RequestCredential> ADLogin(RequestCredential rc) { try { DirectoryEntry de = new DirectoryEntry("", String.Format(@"{0}\{1}", rc.Domain, rc.UserName), rc.Password); //object obj = de.NativeObject; DirectorySearcher search = new DirectorySearcher(de); search.Filter = String.Format("(SAMAccountName={0})", rc.UserName); search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (result == null) { return(new GeneralResponse <RequestCredential>(1, "User Name or Password is not valid")); } rc.Token = Guid.NewGuid().ToString(); AddCredential(rc); return(new GeneralResponse <RequestCredential>(rc)); } catch (Exception ex) { return(new GeneralResponse <RequestCredential>(2, ex.Message)); } }
public GeneralResponse <RequestCredential> Loging(RequestCredential credential) { return(new LoginServiceHanlder().Login(credential)); }