public void Remove(Uri myUri, string aType, NetworkCredential nc)
 {
     for (int ndx = 0; ndx < aList.Count; ndx++)
     {
         CredInfo ci = aList[ndx];
         if (myUri.Equals(ci.uriObj) && aType.Equals(ci.authenType))
         {
             aList.RemoveAt(ndx);
         }
     }
 }
        public NetworkCredential GetCredential(Uri myUri, string aType)
        {
            NetworkCredential retCred = null;

            for (int ndx = 0; ndx < aList.Count; ndx++)
            {
                CredInfo ci = aList[ndx];
                if (myUri.Equals(ci.uriObj) && aType.Equals(ci.authenType))
                {
                    retCred = ci.netCredObj;
                }
            }
            return(retCred);
        }
        public CommonResponse SaveCred(string password, int pin, CredInfo cred)
        {
            try
            {
                if (!CheckAuth(password, pin))
                {
                    return(InvalidAuthResponse());
                }

                config.SaveCred(cred);

                return(SuccessfulResponse());
            }
            catch (Exception ex)
            {
                return(ErrorResponse(ex.Message));
            }
        }
Beispiel #4
0
        public CommonResponse SaveCred(string password, int pin, CredInfo cred)
        {
            try
            {
                if (!CheckAuth(password, pin))
                {
                    return(InvalidAuthResponse());
                }

                var curLvl    = CurrentLevel(password, pin);
                var dbCredLvl = curLvl;
                var q0        = config.Credentials.FirstOrDefault(w => w.GUID == cred.GUID);
                if (q0 != null)
                {
                    dbCredLvl = q0.Level;
                }

                var canEditLevel =
                    curLvl == 99 ||                                                // superuser
                    (string.IsNullOrEmpty(cred.GUID) && cred.Level >= curLvl) ||   // can't create lower level sec credentials
                    (!string.IsNullOrEmpty(cred.GUID) && cred.Level == dbCredLvl); // can't change existing item level

                if (!canEditLevel)
                {
                    return(InvalidAuthResponse());
                }

                config.SaveCred(cred);

                return(SuccessfulResponse());
            }
            catch (Exception ex)
            {
                return(ErrorResponse(ex.Message));
            }
        }