MonkeyFist.Services.Authenticator.AuthenticateUser C# (CSharp) Method

AuthenticateUser() public method

public AuthenticateUser ( Credentials creds ) : AuthenticationResult
creds Credentials
return AuthenticationResult
        public AuthenticationResult AuthenticateUser(Credentials creds)
        {
            _session = new Session();
              var result = new AuthenticationResult();
              User user = null;
              this.CurrentCredentials = creds;

              if (EmailOrPasswordNotPresent()) {
            result = InvalidLogin(Properties.Resources.EmailOrPasswordMissing);
              } else {
            //find the user
            user = LocateUser();

            //if they're not here, we're done
            if (user == null) {
              result = InvalidLogin(Properties.Resources.InvalidLogin);

              //does the password match?
            } else if (HashedPasswordDoesNotMatch(user)) {
              result = InvalidLogin(Properties.Resources.InvalidLogin);

              //success
            } else {
              //success!
              user.AddLogEntry("Login", "User logged in");
              result.Session = CreateSession(user);

              SetUserLoginStats(user);
              //save changes
              UserAuthenticated(user);

              result.Authenticated = true;
              result.User = user;
              result.Message = Properties.Resources.UserAuthenticated;

              _session.SaveChanges();
            }
              }

              //dispose of this
              _session.Dispose();

              return result;
        }

Usage Example

Ejemplo n.º 1
0
        public ValidLogin()
        {
            //register the new user...
              var app = new Application("*****@*****.**", "password", "password");
              new Registrator().ApplyForMembership(app);

              var auth = new Authenticator();
              _result = auth.AuthenticateUser(new Credentials { Email = "*****@*****.**", Password = "******" });
        }