public virtual IPrincipal Login(ILoginCredential credential, EntityManager entityManager) { if (credential == null) { throw new LoginException(LoginExceptionType.NoCredentials, "Credentials are required."); } if (string.IsNullOrWhiteSpace(credential.UserName)) { throw new LoginException(LoginExceptionType.InvalidUserName, "Username cannot be empty."); } if (string.IsNullOrWhiteSpace(credential.Password)) { throw new LoginException(LoginExceptionType.InvalidPassword, "Password cannot be empty."); } var em = new SecurityEntities(entityManager); User user = em.Users.FirstOrDefault(u => u.Username.ToUpper() == credential.UserName.ToUpper()); if (user == null || !user.Authenticate(credential.Password)) { throw new LoginException(LoginExceptionType.InvalidPassword, credential.Domain, credential.UserName); } return(new UserPrincipal(user.Id, new UserIdentity(user.Username, "FORM", true))); }
public virtual IPrincipal Login(ILoginCredential credential, EntityManager entityManager) { if (credential == null) throw new LoginException(LoginExceptionType.NoCredentials, "Credentials are required."); if (string.IsNullOrWhiteSpace(credential.UserName)) throw new LoginException(LoginExceptionType.InvalidUserName, "Username cannot be empty."); if (string.IsNullOrWhiteSpace(credential.Password)) throw new LoginException(LoginExceptionType.InvalidPassword, "Password cannot be empty."); var em = new SecurityEntities(entityManager); User user = em.Users.FirstOrDefault(u => u.Username.ToUpper() == credential.UserName.ToUpper()); if (user == null || !user.Authenticate(credential.Password)) throw new LoginException(LoginExceptionType.InvalidPassword, credential.Domain, credential.UserName); return new UserPrincipal(user.Id, new UserIdentity(user.Username, "FORM", true)); }