private void loginInput_Validating(object sender, CancelEventArgs e) { string input = loginInput.Text; if (string.IsNullOrEmpty(input)) { errorProvider1.SetError(loginInput, "Please enter your login!"); } else if (input.Length < 6) { errorProvider1.SetError(loginInput, "Login should be at least 6 digits long!"); } else if (!CredentialsValidator.IsValid(input)) { errorProvider1.SetError(loginInput, "Login contains forbidden symbols!"); } else if (Main.HospitalStructure.Employees.Any(any => any.Login == input)) { errorProvider1.SetError(loginInput, "This login is already used!"); } else { errorProvider1.SetError(loginInput, null); } }
public string GenerateToken() { ICredentialsValidator validator = new CredentialsValidator(); if (validator.IsValid()) { return(new TokenBuilder().Build()); } throw new InvalidCredentialException("Credencial inválida."); }
public string Authenticate(Credentials creds) { CredentialsValidator validator = new CredentialsValidator(); if (validator.IsValid(creds)) { return(new TokenBuilder().Build(creds)); } throw new InvalidOperationException("Invalid credentials"); }
private void loginInput_Validating(object sender, CancelEventArgs e) { if (string.IsNullOrEmpty(loginInput.Text)) { errorProvider1.SetError(loginInput, "Please enter your login!"); } else if (loginInput.Text.Length < 6) { errorProvider1.SetError(loginInput, "Login should be at least 6 digits long!"); } else if (!CredentialsValidator.IsValid(loginInput.Text)) { errorProvider1.SetError(loginInput, "Login contains forbidden symbols!"); } else { errorProvider1.SetError(loginInput, null); } }
private void surnameInput_Validating(object sender, CancelEventArgs e) { string input = surnameInput.Text; if (string.IsNullOrEmpty(input)) { errorProvider1.SetError(surnameInput, "Please enter surname!"); } else if (input.Length < 2) { errorProvider1.SetError(surnameInput, "Surname should be at least 2 digits long!"); } else if (!CredentialsValidator.IsValid(input)) { errorProvider1.SetError(surnameInput, "Surname contains forbidden symbols!"); } else { errorProvider1.SetError(surnameInput, null); } }
/// <summary> /// Loads the authenticator plugins and tries to authenticate to each of them. /// </summary> /// <param name="creds">The credentials, user name and password, to authenticate with.</param> /// <returns>A token if authenticated.</returns> /// <exception>AuthenticationException</exception> public IToken Authenticate(Credentials creds) { if (creds == null && WebOperationContext.Current != null) { var basicAuthHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"]; if (!string.IsNullOrWhiteSpace(basicAuthHeader)) { creds = new BasicAuth(basicAuthHeader).Creds; } } IToken token; if (CredentialsValidator.IsValid(creds, out token)) { return(token); } else { throw new AuthenticationException("Invalid credentials."); } }