public void EmailValidator_ExcludeDomains() { EmailValidator testSubject = new EmailValidator("message {0}", "tag", false) { Category = EmailCategory.Basic, AllowComments = false, AllowIPAddresses = false, RequireTopLevelDomain = false, IncludeDomains = null, ExcludeDomains = "*evil.o?g;nowhere.com" }; string input = "*****@*****.**"; EntLib.ValidationResults results = testSubject.Validate(input); Assert.IsTrue(results.IsValid); input = "*****@*****.**"; results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); input = "*****@*****.**"; results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); input = "*****@*****.**"; results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); input = "*****@*****.**"; results = testSubject.Validate(input); Assert.IsTrue(results.IsValid); }
public void CheckValidEmails() { var validator = new EmailValidator(); Assert.IsTrue(validator.Validate("*****@*****.**")); Assert.IsTrue(validator.Validate("*****@*****.**")); }
private void BtnRegister_OnClick(object sender, ClickedEventArgs e) { //making sure that passwords match and the email has been successfully validated if (txtPassword.Text == txtRepeat.Text && eValidator.Validate(txtEmail.Text)) { if (!GameClient.NetClient.Connected) { GameClient.NetClient.Connect(); } if (!GameClient.NetClient.Connected) { DisplayMessage("Connection to game server could not be found!"); } else { //if we have connected to the game server and everything checks out, we're going to register to the server PacketBuilder pb = new PacketBuilder(PacketFamily.REGISTER, PacketAction.REQUEST); pb = pb.AddByte((byte)txtUsername.Text.Length) .AddString(txtUsername.Text) .AddByte((byte)txtPassword.Text.Length) .AddString(txtPassword.Text) .AddByte((byte)txtEmail.Text.Length) .AddString(txtEmail.Text) .AddByte((byte)txtFullname.Text.Length) .AddString(txtFullname.Text); GameClient.NetClient.Send(pb.Build()); } } }
public void EmailValidator_IPFilter() { EmailValidator testSubject = new EmailValidator("message {0}", "tag", false) { AllowComments = false, AllowIPAddresses = true, RequireTopLevelDomain = false, IncludeDomains = "192.168.10.23;10.12.*", ExcludeDomains = "36.45.12.63;10.12.9.*" }; string input = "user@[17.45.26.95]"; EntLib.ValidationResults results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); input = "user@[192.168.10.23]"; results = testSubject.Validate(input); Assert.IsTrue(results.IsValid); input = "user@[36.45.12.63]"; results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); input = "user@[10.12.45.125]"; results = testSubject.Validate(input); Assert.IsTrue(results.IsValid); input = "user@[10.12.9.152]"; results = testSubject.Validate(input); Assert.IsFalse(results.IsValid); }
public void CheckInvalidEmails() { var validator = new EmailValidator(); Assert.IsFalse(validator.Validate("name [email protected]")); Assert.IsFalse(validator.Validate("prefix@suffix")); }
public void Should_invalid_wrong_address(string address) { Email email = new Email(address); ValidationResult results = validator.Validate(email); Assert.False(results.IsValid); }
public void When_email_address_contains_upper_cases_then_the_validator_should_pass() { string email = "*****@*****.**"; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeTrue(); email = "*****@*****.**"; result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeTrue(); }
public void ShouldReturnFalseForEmptyObject() { object testValue = new object(); Validator emailValidator = new EmailValidator(testValue); Assert.IsFalse(emailValidator.Validate()); }
public bool EmailIsValid(string email) { var tt = EmailValidator.Validate(email); Console.WriteLine(tt); return(tt); }
public async Task <ResponseWithModel <User> > CreateUser(CreateUserRequestModel createUserModel) { if (!EmailValidator.Validate(createUserModel.Email)) { return(ResponseWithModel <User> .Unsuccessful("This email does not uphold conventions")); } //User to be inserted var user = new User { Id = Guid.NewGuid(), Created = DateTime.UtcNow, Email = createUserModel.Email.ToLower(), LastLogin = DateTime.UtcNow, Password = BCrypt.Net.BCrypt.HashPassword(createUserModel.Password), AuthLevel = createUserModel.AuthLevel, }; var response = await _userRepository.CreateUser(user); if (!response.IsSuccessful) { return(ResponseWithModel <User> .Unsuccessful(response.Message)); } return(ResponseWithModel <User> .Successfull(user)); }
public void TestInvalidAddresses() { for (int i = 0; i < InvalidAddresses.Length; i++) { Assert.False(EmailValidator.Validate(InvalidAddresses[i]), String.Format("Invalid Address #{0}", i)); } }
public void TestValidAddresses() { for (int i = 0; i < ValidAddresses.Length; i++) { Assert.True(EmailValidator.Validate(ValidAddresses[i]), String.Format("Valid Address #{0}", i)); } }
private void ValidateEmailAddress(string email) { if (!EmailValidator.Validate((email ?? string.Empty).Trim())) { throw new ApplicationException("Email is not valid."); } }
public void ShouldReturnFalseForValueType() { decimal testValue = 12345; Validator emailValidator = new EmailValidator(testValue); Assert.IsFalse(emailValidator.Validate()); }
public void Test5() { const string _email = ""; var _rc = EmailValidator.Validate(_email, true); Assert.AreEqual(_rc, true); }
/// <summary> /// POST api/CustomRegistration /// </summary> public HttpResponseMessage Post(RegistrationRequest Request) { // Validate the email format if (!EmailValidator.Validate(Request.Email, true)) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid email format")); } // Validate the password else if (Request.Password.Length < 6) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid password (at least 8 chars required)")); } // Use local database context for testing local to service //alltheairgeadmobileContext context = new alltheairgeadmobileContext(); // Setup the database connection to the remote server alltheairgeadContext context = new alltheairgeadContext(Services.Settings["ExistingDbConnectionString"]); // Check that the account doesn't already exist UserProfile account = context.UserProfiles.Where(a => a.Email == Request.Email).SingleOrDefault(); if (account != null) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Email already exists")); } // Otherwise create a new account else { // Build new account from provided email. UserProfile newAccount = new UserProfile { Email = Request.Email }; // Add the email to the userprofiles table context.UserProfiles.Add(newAccount); context.SaveChanges(); // Get autogenerated UserId to use. newAccount = context.UserProfiles.Where(a => a.Email == Request.Email).SingleOrDefault(); // Build a new membership item for the webpages_Membershup table webpages_Membership newMembership = new webpages_Membership { UserId = newAccount.UserId, CreateDate = DateTime.Now, IsConfirmed = true, LastPasswordFailureDate = null, PasswordFailuresSinceLastSuccess = 0, Password = Crypto.HashPassword(Request.Password), PasswordChangedDate = null, PasswordSalt = "blank", PasswordVerificationToken = null, PasswordVerificationTokenExpirationDate = null }; // Add to the table context.Memberships.Add(newMembership); context.SaveChanges(); // Return the successful response return(this.Request.CreateResponse(HttpStatusCode.Created)); } }
public Notification Validate(FormData formData, EmailData emailData) { Notification result = new Notification(); string message = string.Empty; if (!FirstNameValidator(formData.FirstName)) { result.AddMessage("First name is invalid!"); } if (!LastNameValidator(formData.LastName)) { result.AddMessage("Last name is invalid!"); } if (!CommentsValidator(formData.Comments)) { result.AddMessage("Comments are invalid!"); } if (!emailValidator.Validate(emailData.ToAddress)) { result.AddMessage("Email address is invalid!"); } if (!SmtpHostValidator(emailData.SmtpHost)) { result.AddMessage("Smtp host is invalid!"); } return(result); }
public async void SendEmailToAll(string subject, string body, string senderEmail, string senderName, string senderPassword) { SmtpServer = new SmtpClient("smtp.gmail.com") { Port = 587, Credentials = new NetworkCredential(senderEmail, senderPassword), EnableSsl = true }; await Task.Run(() => { foreach (Recipient recipient in recipients) { if (EmailValidator.Validate(recipient.EmailAddress)) { MailMessage message = new MailMessage(); message.From = new MailAddress(senderEmail); message.To.Add(recipient.EmailAddress); message.Subject = subject; message.Body = body; SmtpServer.Send(message); Console.WriteLine($"Sending email to {message.To}"); } else { Console.WriteLine("Invalid Email"); } } }); Console.WriteLine("Email sent"); }
public async Task <ResponseMessage> UpdateEmail(Guid userId, string email, string password) { var validation = EmailValidator.Validate(email); if (!EmailValidator.Validate(email)) { return(new ResponseMessage(false, null, null, "Must enter valid email address")); } var result = await userStore.FindUserByEmail(email); if (result != null) { return(new ResponseMessage(false, null, null, "Email already taken")); } //Check if the password match var user = await userStore.FindUserById(userId); if (user == null) { return(new ResponseMessage(false, null, null, "Unauthorized userId")); } if (!BCrypt.Net.BCrypt.Verify(password, user.Password)) { return(new ResponseMessage(false, null, null, "Incorrect password")); } await userStore.UpdateEmail(userId, email); return(new ResponseMessage(true)); }
public void EmailValidator_Validate() { Assert.IsTrue(EmailValidator.Validate("*****@*****.**")); Assert.IsTrue(EmailValidator.Validate("*****@*****.**")); Assert.IsFalse(EmailValidator.Validate("john.smith.53@mailservice")); // No .something Assert.IsFalse(EmailValidator.Validate("john.smith.53mailservice.uk")); // No '@' }
protected void btnEnviarMdl_Click(object sender, EventArgs e) { string correo = txtCorreoDl.Text.Trim(); EmailValidator emailValidator = new EmailValidator(); EmailValidationResult resultEmail; string resultadoCorreo = ""; bool c = emailValidator.Validate(correo, out resultEmail); resultadoCorreo = resultEmail.ToString(); if (resultadoCorreo == "OK") { pa_InsertarDelegadoParticipante_Result result = participanteService.insertarDelegadoParticipante(new insertarDelegadoParticipanteParams { apMaternoPersona = txtApellidoMaternoDl.Text.Trim(), apPaternoPersona = txtApellidoMaternoDl.Text.Trim(), nombrePersona = txtNombreDl.Text.Trim(), correo_Usuario = txtCorreoDl.Text.Trim(), puestoPersona = txtPuestoDl.Text.Trim(), organizacionPersona = txtOrganizacionDl.Text.Trim(), nroDocumentoPersona = txtNumeroDocumentoDl.Text.Trim(), id_Participante = int.Parse(Session["id_Participante"].ToString()), id_TipoDocumento = Convert.ToInt32(dplTipoDocumentoDl.SelectedValue) }); if (result.errorstatus == true) { Div2.Visible = true; } else { Div1.Visible = true; Response.Redirect("Login.aspx"); } } else { txtCorreoDl.Text = "Ingresar correo Valido"; txtCorreoDl.Focus(); } }
public void Test2() { const string _email = "*****@*****.**"; var _rc = EmailValidator.Validate(_email, true); Assert.AreEqual(_rc, true); }
public async Task <ActionResult <MessageFromPastSelf> > PostMessageFromPastSelf( MessageFromPastSelfDto messageFromPastSelfdto) { if (!EmailValidator.Validate(messageFromPastSelfdto.To) || messageFromPastSelfdto.Body.Length < 1) { return(BadRequest()); } MessageFromPastSelf messageFromPastSelf = new MessageFromPastSelf { Body = messageFromPastSelfdto.Body, IsBodyHtml = messageFromPastSelfdto.IsBodyHtml, Subject = messageFromPastSelfdto.Subject, To = messageFromPastSelfdto.To, when = messageFromPastSelfdto.when }; _context.messages.Add(messageFromPastSelf); await _context.SaveChangesAsync(); var jobid = _mailService.scheduleEmail(messageFromPastSelf); messageFromPastSelf.jobid = jobid; return(CreatedAtAction("GetMessageFromPastSelf", new { id = messageFromPastSelf.Id }, messageFromPastSelf)); }
public void This_should_not_hang() { string email = "thisisaverylongstringcodeplex.com"; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeFalse(); }
private async Task <IEnumerable <string> > ValidateEmailAsync(User user) { var errors = new List <string>(); if (!string.IsNullOrWhiteSpace(user.Email)) { if (!EmailValidator.Validate(user.Email)) { errors.Add(string.Format(CultureInfo.CurrentCulture, Resource.InvalidEmail, user.Email)); } else { var existingUser = await this.userRepository.FindByEmailAsync(user.UserName); if (existingUser != null && existingUser.Id != user.Id) { errors.Add(string.Format(CultureInfo.CurrentCulture, Resource.DuplicateEmail, user.Email)); } } } else { errors.Add(string.Format(CultureInfo.CurrentCulture, Resource.PropertyTooShort, EmailPropertyName)); } return(errors); }
private void button1_Click(object sender, RoutedEventArgs e) { if (txtemail.Text.Trim() != "" && txtname.Text.Trim() != "" && txtpassword.Password.Trim() != "") { string emailId = txtemail.Text.Trim().ToLower(); if (emailId == null || !EmailValidator.Validate(emailId)) { txtemail.Background = Colors.errorBackGround; txtemail.Foreground = Colors.errorForeGround; return; } string name = txtname.Text.Trim(); string password = txtpassword.Password.Trim(); try { AWSConnectionService db = AWSConnectionService.getInstance(); db.createRegistrationTableIfNotExists(); db.insertIntoRegistrationTableIfNotExist(emailId, password, name); new Login().Show(); this.Hide(); Console.WriteLine("To continue, press Enter"); Console.ReadLine(); } catch (AmazonDynamoDBException ex) { Console.WriteLine(ex.Message); } catch (AmazonServiceException ex) { Console.WriteLine(ex.Message); } } else { MessageBox.Show("Please fill all details"); } }
public TUser CreateActiveUser(TCreateUserForm form) { EmailValidator.Validate(form.Login); var existingUser = userStorage.FindUserByLogin(form.Login); if (existingUser != null) { if (existingUser.IsActive) { throw new LoginAlreadyExistsException(form.Login); } throw new LoginAlreadyExistsButNeedsActivationException(form.Login); } var userId = Guid.NewGuid(); var utcNow = DateTimeOffset.UtcNow; var user = userProcessor.MakeUser(form, userId); user.DateTimeActivated = utcNow; SetUserPassword(user, form.Password); userStorage.CreateUser(user); return(userStorage.FindUser(userId)); }
public async Task NewUser(string Email, string Password, string FirstName, string LastName) { if (EmailValidator.Validate(Email)) { try { using (ITransaction transaction = _session.BeginTransaction()) { var user = new User { Email = Email, Password = Password, FirstName = FirstName, LastName = LastName }; await _session.SaveAsync(user); await transaction.CommitAsync(); } } catch { throw new NewUserInsertException(_path, "NewUser()"); } finally { _nHibernateService.CloseSession(); } } else { throw new NewUserEmailException(_path, "NewUser()"); } }
public TUser CreateUserAndActivationRequest(TCreateUserForm form, Uri activateUserUrl) { var login = form.Login.Trim(); if (!EmailValidator.Validate(login)) { throw new IncorrectEmailException(); } var password = form.Password; if (!passwordValidator.Validate(password)) { throw new WeakPasswordException(); } var existingUser = userStorage.FindUserByLogin(login); if (existingUser != null) { throw new LoginAlreadyExistsException(login); } var userId = Guid.NewGuid(); var user = userProcessor.MakeUser(form, userId); SetUserPassword(user, password); userStorage.CreateUser(user); SendUserActivationRequest(user, activateUserUrl); return(userStorage.FindUser(userId)); }
public void EmailValidator_Configuration_NamedValidator() { EmailValidator testSubject = new EmailValidator("Custom Validator", "message {0}", "tag", false); string input = "*****@*****.**"; EntLib.ValidationResults results = testSubject.Validate(input); Assert.IsFalse(results.IsValid, input); input = "user@[127.251.42.88]"; results = testSubject.Validate(input); Assert.IsTrue(results.IsValid, input); input = "user(my comment)@[127.251.42.88]"; results = testSubject.Validate(input); Assert.IsTrue(results.IsValid, input); }
public bool Subscribe(string email) { if (string.IsNullOrWhiteSpace(email)) { throw new ArgumentNullException(nameof(email)); } email = email.Trim(); if (EmailValidator.Validate(email) == false) { Logger.Instance.Log(Logger.Level.Warn, $"유효하지 않은 이메일 주소, '{email}'"); return(false); } Subscriber subscriber = new Subscriber(email); if (subscriberTable.ContainsKey(subscriber.Id)) { Logger.Instance.Log(Logger.Level.Warn, $"이미 등록된 이메일 주소, '{email}'"); return(false); } if (DatabaseManager.Instance.AddSubscriber(subscriber) == false) { Logger.Instance.Log(Logger.Level.Error, $"데이터베이스에 구독자 등록 실패, '{subscriber}'"); return(false); } subscriberTable.Add(subscriber.Id, subscriber); return(true); }
public async Task <IActionResult> PutMessageFromPastSelf(long id, MessageFromPastSelf messageFromPastSelf) { if (id != messageFromPastSelf.Id || !EmailValidator.Validate(messageFromPastSelf.To) || messageFromPastSelf.Body.Length < 1) { return(BadRequest()); } var jobid = _mailService.updateEmail(messageFromPastSelf); messageFromPastSelf.jobid = jobid; _context.Entry(messageFromPastSelf).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MessageFromPastSelfExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void When_the_text_is_a_valid_email_address_including_plus_validator_should_pass() { string email = "*****@*****.**"; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeTrue(); }
public void Email_Valid() { string email = "*****@*****.**"; var emailVal = new EmailValidator(); var valResult = emailVal.Validate(email); Assert.IsTrue(valResult.IsValid); }
public void TestUnableToTest() { EmailValidator emailValidator = new EmailValidator(); IList<string> emails = new List<string>() { "*****@*****.**", }; foreach (string email in emails) { EmailValidationResult result; if (emailValidator.Validate(email, out result)) { Assert.Fail("Actually was able to test :) " + email); } Assert.AreEqual(EmailValidationResult.MailServerUnavailable, result, email); } }
public void TestAvailable() { EmailValidator emailValidator = new EmailValidator(); IList<string> emails = new List<string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**", }; foreach (string email in emails) { EmailValidationResult result; if (!emailValidator.Validate(email, out result)) { Assert.Fail("Unable to test " + email); } Assert.AreEqual(EmailValidationResult.OK, result, email); } }
public void TestInvalidDomain() { EmailValidator emailValidator = new EmailValidator(); IList<string> emails = new List<string>() { "*****@*****.**", "*****@*****.**", "mail@по-кружке.рф", }; foreach (string email in emails) { EmailValidationResult result; if (!emailValidator.Validate(email, out result)) { Assert.Fail("Unable to test " + email); } Assert.AreEqual(EmailValidationResult.NoMailForDomain, result, email); } }
public void TestMailboxUnavailable() { EmailValidator emailValidator = new EmailValidator(); EmailValidationResult result; if (!emailValidator.Validate("*****@*****.**", out result)) { Assert.Fail("Unable to test email"); } Assert.AreEqual(EmailValidationResult.MailboxUnavailable, result); }
public void When_validation_fails_the_default_error_should_be_set() { string email = "testperso"; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext("Email", new object(), x => email)); result.Single().ErrorMessage.ShouldEqual("'Email' is not a valid email address."); }
public void TestAddressIsEmpty() { EmailValidator emailValidator = new EmailValidator(); IList<string> emails = new List<string>() { "", " ", null, }; foreach (string email in emails) { EmailValidationResult result; if (!emailValidator.Validate(email, out result)) { Assert.Fail("Unable to test " + email); } Assert.AreEqual(EmailValidationResult.AddressIsEmpty, result, email); } }
public void When_the_text_is_null_then_the_validator_should_pass() { string email = null; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeTrue(); }
public void TestNoMailForDomain() { EmailValidator emailValidator = new EmailValidator(); IList<string> emails = new List<string>() { "*****@*****.**", }; foreach (string email in emails) { EmailValidationResult result; if (!emailValidator.Validate(email, out result)) { Assert.Fail("Unable to test " + email); } Assert.AreEqual(EmailValidationResult.NoMailForDomain, result, email); } }
public void When_the_text_is_not_a_valid_email_address_then_the_validator_should_fail() { string email = "testperso"; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeFalse(); }
public void When_the_text_is_empty_then_the_validator_should_fail() { string email = String.Empty; var validator = new EmailValidator(); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => email)); result.IsValid().ShouldBeFalse(); }