Beispiel #1
0
 public bool ReplaceCredential(IUserIdentity user, Security.ICredential existing, Security.ICredential proposed)
 {
     if (user != null && existing != null && proposed != null)
     {
         UserPasswordCredential toRemove = existing as UserPasswordCredential; //this is the only type of credential we can use
         UserPasswordCredential toAdd    = proposed as UserPasswordCredential; //this is the only type of credential we can use
         if (toRemove != null && toAdd != null)
         {
             PersistedCredential cred = GetPersisted(user.Uid, toRemove.UserName.ToLowerInvariant());
             if (cred != null && toRemove.Matches(cred)) //has to be currently valid to do a replace
             {
                 UsernamePassword up = toAdd.ToHistoryPair();
                 if (toRemove.UserName.ToLowerInvariant().Equals(toAdd.UserName.ToLowerInvariant()))
                 {
                     PasswordHistory <UsernamePassword> hist = GetHistory(user.Uid, up.UserName);
                     if (!hist.MatchesHistory(UsernamePassword.Matches, up)) //check for historic collision
                     {
                         if (ReplaceCredential(user.Uid, up.UserName, up.Password))
                         {
                             hist.Add(up);
                             this.historyProvider.Update(user.Uid, hist);
                             return(true);
                         }
                     }
                 }
                 else //different usernames being used
                 {
                     if (this.storeProvider.DeleteCredential(user.Uid, this, toRemove.UserName.ToLowerInvariant()))
                     {
                         this.historyProvider.Delete(user.Uid); //TODO -- this we need to fix by userId,type
                         if (this.storeProvider.AddCredential(user.Uid, this, up.UserName, up.Password))
                         {
                             PasswordHistory <UsernamePassword> hist = GetHistory(user.Uid, up.UserName);
                             this.historyProvider.Update(user.Uid, hist);
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
Beispiel #2
0
 public bool Authenticates(Security.ICredential credential)
 {
     if (credential != null)
     {
         UserPasswordCredential up = credential as UserPasswordCredential;
         if (up != null)
         {
             IEnumerable <PersistedCredential> creds = this.storeProvider.Get(this, up.UserName.ToLowerInvariant());
             if (creds != null)
             {
                 foreach (PersistedCredential cur in creds)
                 {
                     if (up.Matches(cur))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Beispiel #3
0
 public IUserIdentity Authenticate(Security.ICredential credential)
 {
     if (credential != null)
     {
         UserPasswordCredential up = credential as UserPasswordCredential;
         if (up != null)
         {
             IEnumerable <PersistedCredential> creds = this.storeProvider.Get(this, up.UserName.ToLowerInvariant());
             if (creds != null)
             {
                 foreach (PersistedCredential cur in creds)
                 {
                     if (up.Matches(cur))
                     {
                         return(IdentityManager.Instance.GetProvider(this.Context).Get(cur.UserId));
                     }
                 }
             }
         }
     }
     return(null);
 }