public static string GetCurrentLocalADDomain() { ADValidation auth = new ADValidation(); if (LocalADCurrentDomain == null) { string theDnsHostNameRootDSE = auth.RetrieveDnsHostNameRootDseDefaultNamingContext(); if (theDnsHostNameRootDSE != null) { string[] subStrings = theDnsHostNameRootDSE.Split('|'); if (subStrings.Length > 0) { LocalADCurrentDomain = subStrings[0]; } } } return(LocalADCurrentDomain ?? string.Empty); }
//1dii creates a validate method public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { OECContext _context = OEC_Singleton.Context(); //trimm all strings of leading and trailing spaces if (Name != null) { Name = Name.ToLower().Trim(); Name = ADValidation.ADCapitalize(Name); } if (Address != null) { Address = Address.ToLower().Trim(); Address = ADValidation.ADCapitalize(Address); } if (Town != null) { Town = Town.ToLower().Trim(); Town = ADValidation.ADCapitalize(Town); } if (County != null) { County = County.ToLower().Trim(); County = ADValidation.ADCapitalize(County); } if (ProvinceCode != null) { ProvinceCode = ProvinceCode.Trim(); ProvinceCode = ProvinceCode.ToUpper(); } if (PostalCode != null) { PostalCode = PostalCode.Trim(); } if (Email != null) { Email = Email.Trim(); } if (Directions != null) { Directions = Directions.Trim(); } //either the town or country must be provided if (String.IsNullOrWhiteSpace(Town) && String.IsNullOrWhiteSpace(County)) { yield return(new ValidationResult("At least one town or country must be provided.")); } if (String.IsNullOrWhiteSpace(Email)) { if (String.IsNullOrWhiteSpace(Address) || String.IsNullOrWhiteSpace(PostalCode)) { yield return(new ValidationResult("If no email, you must provide an address and postal code.")); } } //if postal code provided, validate and format it using postalcodevalidation or zipcode validation, depending which country if (!String.IsNullOrWhiteSpace(PostalCode)) { if (!String.IsNullOrWhiteSpace(ProvinceCode)) { var countryCode = ""; if (ProvinceCode.Length == 2) { countryCode = _context.Province.SingleOrDefault(p => p.ProvinceCode == ProvinceCode).CountryCode; } else { countryCode = _context.Province.SingleOrDefault(p => p.Name == ProvinceCode).CountryCode; } string postalCode = PostalCode; if (countryCode == "CA") { if (!ADValidation.ADPostalCodeValidation(ref postalCode)) { yield return(new ValidationResult("Postal Code is not a valid pattern (N5G 6Z6)", new string[] { nameof(PostalCode) })); } else { PostalCode = postalCode; } } if (countryCode == "US") { if (!ADValidation.ADZipCodeValidation(ref postalCode)) { yield return(new ValidationResult("Zip Code is not a valid pattern (12345 or 12345-1234)", new string[] { nameof(PostalCode) })); } PostalCode = postalCode; } } } //either home phone or cellphone must be provided if (String.IsNullOrWhiteSpace(HomePhone) && String.IsNullOrWhiteSpace(CellPhone)) { yield return(new ValidationResult("You must provide either your cell or home phone number.")); } else { Regex pattern = new Regex(@"\d{10}", RegexOptions.IgnoreCase); if (!String.IsNullOrWhiteSpace(HomePhone)) { //get rid of all punctuation and trim and space HomePhone = Regex.Replace(HomePhone, @"[^\w\s]", "").Trim(); HomePhone = Regex.Replace(HomePhone, "[^0-9]", ""); if (!pattern.IsMatch(HomePhone)) { yield return(new ValidationResult("Home phone is incorrect pattern: ", new string[] { nameof(HomePhone) })); } else { //insert dashes into phone number HomePhone = Regex.Replace(HomePhone, @"^(...)(...)(....)$", "$1-$2-$3"); } } if (!String.IsNullOrWhiteSpace(CellPhone)) { //get rid of all punctuation and trim and space CellPhone = Regex.Replace(CellPhone, @"[^\w\s]", "").Trim(); CellPhone = Regex.Replace(CellPhone, "[^0-9]", ""); if (!pattern.IsMatch(CellPhone)) { yield return(new ValidationResult("Cell phone is incorrect pattern: ", new string[] { nameof(CellPhone) })); } else { //insert dashes into phone number CellPhone = Regex.Replace(CellPhone, @"^(...)(...)(....)$", "$1-$2-$3"); } } } //lastcontact date cantbe provided unless datejoined if (LastContactDate != null && DateJoined == null) { yield return(new ValidationResult("You must also provide Date Joined.", new string[] { nameof(DateJoined) })); } //last contact date cant be before date joined if (DateJoined > LastContactDate) { yield return(new ValidationResult("Last contact date can not be prior to date joined.")); } //1diii replace the throw statement yield return(ValidationResult.Success); //throw new NotImplementedException(); }
private void btnValidate_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtSAMAccountName.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("User Name and Password is required."); return; } try { bool IsUserAuthenticated = false; bool IsUserAuthorized = false; theDnsHostNameRootDSE = ""; theDnsHostName = ""; theRootDSE = ""; // Non-privileged local user account on a domain PC returns this error: // "The specified domain either does not exist or could not be contacted." //theDnsHostNameRootDSE = ADValidation.RetrieveDnsHostNameRootDseDefaultNamingContext(); //MessageBox.Show("'" + theDnsHostNameRootDSE + "'"); //string[] subStrings = theDnsHostNameRootDSE.Split('|'); //theDnsHostName = subStrings[0]; //theRootDSE = subStrings[1]; //theDnsHostName = "RDADC.rda.local"; // Login Authenticated! - Authorization Failed! //MessageBox.Show("'" + theDnsHostName + "'"); theDnsHostName = "rda.local"; // Login Authenticated! - Authorization Failed! MessageBox.Show("'" + theDnsHostName + "'"); //theDnsHostName = "rda"; // Login Authenticated! - Authorization Failed! //MessageBox.Show("'" + theDnsHostName + "'"); IsUserAuthenticated = ADValidation.IsUserValidated(txtSAMAccountName.Text, theDnsHostName, txtPassword.Text); //MessageBox.Show("IsAuthenticated = " + IsUserAuthenticated); if (IsUserAuthenticated) { // The login is authenticated MessageBox.Show("Login Authenticated!"); } else { MessageBox.Show("Login Failed!"); ClearForm1(); throw new InvalidCredentialException(); } IsUserAuthorized = ADValidation.IsUserInGroup(txtSAMAccountName.Text, theDnsHostName, txtAppGroup.Text); //MessageBox.Show("IsUserAuthorized = " + IsUserAuthorized); if (IsUserAuthorized) { // The application is authorized for the user MessageBox.Show("Application Authorized!"); } else { MessageBox.Show("Authorization Failed!"); ClearForm1(); throw new InvalidCredentialException(); } ClearForm1(); } catch (Exception ex) { MessageBox.Show(ex.Message + "ADT05 Message!" + System.Environment.NewLine + "'" + txtAppGroup.Text + "'" + System.Environment.NewLine + "'" + txtSAMAccountName.Text + "'" + System.Environment.NewLine + "'" + theDnsHostName + "'" + System.Environment.NewLine); } }
private void btnValidate_Click(object sender, EventArgs e) { // ann is commenting if (string.IsNullOrWhiteSpace(txtAppGroup.Text) || string.IsNullOrWhiteSpace(txtSAMAccountName.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("Application Group, User Name, and Password is required."); txtOutput.Text += "Application Group, User Name, and Password is required." + " \r\n"; return; } try { // string result = COMTest.ValidateCredentialsTLS(theUserName, theUserDomainName, theUserPassword, out serverName); // txtOutput.Text = result; bool IsUserAuthenticated = false; bool IsUserAuthorized = false; ADValidation ad = new ADValidation(); string theDnsHostNameRootDSE = ""; string theDnsHostName = ""; string theRootDSE = ""; string serverName; theDnsHostNameRootDSE = ad.RetrieveDnsHostNameRootDseDefaultNamingContext(); string[] subStrings = theDnsHostNameRootDSE.Split('|'); theDnsHostName = subStrings[0]; txtOutput.Text += "dnsHostName: " + theDnsHostName + " \r\n"; txtOutput.Text += "Application Group: " + txtAppGroup.Text + " \r\n"; txtOutput.Text += "SAM Account Name: " + txtSAMAccountName.Text + " \r\n"; theRootDSE = subStrings[1]; IsUserAuthenticated = ADValidation.IsUserValidated(txtSAMAccountName.Text, theDnsHostName, txtPassword.Text); bool result = com.Authenticate(txtSAMAccountName.Text, txtPassword.Text, theDnsHostName); //MessageBox.Show("IsAuthenticated = " + IsUserAuthenticated); if (IsUserAuthenticated) { // The login is authenticated txtOutput.Text += string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + " " + txtAppGroup.Text + " " + txtSAMAccountName.Text + " Login Authenticated!" + " \r\n"; MessageBox.Show("Login Authenticated!"); } else { txtOutput.Text += string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + " " + txtAppGroup.Text + " " + txtSAMAccountName.Text + " Login Failed!" + " \r\n"; MessageBox.Show("Login Failed!"); ClearForm1(); throw new InvalidCredentialException(); } IsUserAuthorized = ADValidation.IsUserInGroup(txtSAMAccountName.Text, theDnsHostName, txtAppGroup.Text); result = com.Authorize(txtSAMAccountName.Text, theDnsHostName, txtAppGroup.Text); //MessageBox.Show("IsUserAuthorized = " + IsUserAuthorized); if (IsUserAuthorized) { // The application is authorized for the user txtOutput.Text += string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + " " + txtAppGroup.Text + " " + txtSAMAccountName.Text + " Application Authorized!" + " \r\n"; MessageBox.Show("Application Authorized!"); } else { txtOutput.Text += string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now) + " " + txtAppGroup.Text + " " + txtSAMAccountName.Text + " Authorization Failed!" + " \r\n"; MessageBox.Show("Authorization Failed!"); ClearForm1(); throw new InvalidCredentialException(); } ClearForm1(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }