Example #1
0
        public virtual async Task <TUser> FindByEmailAsync(string email)
        {
            ThrowIfDisposed();
            IUserEmailStore <TUser> emailStore = GetEmailStore();

            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }

            TUser user = await emailStore.FindByEmailAsync(email, CancellationToken);

            if (user == null && Options.Stores.ProtectPersonalData)
            {
                ILookupProtectorKeyRing keyRing   = _services.GetService <ILookupProtectorKeyRing>();
                ILookupProtector        protector = _services.GetService <ILookupProtector>();
                if (keyRing != null && protector != null)
                {
                    foreach (var key in keyRing.GetAllKeyIds())
                    {
                        string oldKey = protector.Protect(key, email);
                        user = await emailStore.FindByEmailAsync(oldKey, CancellationToken);

                        if (user != null)
                        {
                            return(user);
                        }
                    }
                }
            }
            return(user);
        }
Example #2
0
        public async Task <User> FindByPhoneNumberAsync(string phone)
        {
            this.ThrowIfDisposed();
            if (phone == null)
            {
                throw new ArgumentNullException(nameof(phone));
            }
            User byEmailAsync = await(this.Users).FirstOrDefaultAsync((Expression <Func <User, bool> >)(u => u.PhoneNumber == phone), CancellationToken.None);

            if ((object)byEmailAsync == null && this.Options.Stores.ProtectPersonalData)
            {
                ILookupProtectorKeyRing service   = this._services.GetService <ILookupProtectorKeyRing>();
                ILookupProtector        protector = this._services.GetService <ILookupProtector>();
                if (service != null && protector != null)
                {
                    foreach (string allKeyId in service.GetAllKeyIds())
                    {
                        byEmailAsync = await(this.Users).FirstOrDefaultAsync((Expression <Func <User, bool> >)(u => u.PhoneNumber == protector.Protect(allKeyId, phone)), CancellationToken.None);
                        if ((object)byEmailAsync != null)
                        {
                            return(byEmailAsync);
                        }
                    }
                }
                protector = (ILookupProtector)null;
            }
            return(byEmailAsync);
        }
Example #3
0
 private string ProtectPersonalData(string data)
 {
     if (Options.Stores.ProtectPersonalData)
     {
         ILookupProtectorKeyRing keyRing   = _services.GetService <ILookupProtectorKeyRing>();
         ILookupProtector        protector = _services.GetService <ILookupProtector>();
         return(protector.Protect(keyRing.CurrentKeyId, data));
     }
     return(data);
 }
Example #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="keyRing"></param>
 /// <param name="protector"></param>
 public DefaultPersonalDataProtector(ILookupProtectorKeyRing keyRing, ILookupProtector protector)
 {
     _keyRing   = keyRing;
     _encryptor = protector;
 }