예제 #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);
        }
예제 #2
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);
 }
예제 #3
0
        /// <summary>
        /// Protect the data.
        /// </summary>
        /// <param name="data">The data to protect.</param>
        /// <returns>The protected data.</returns>
        public virtual string Protect(string data)
        {
            var current = _keyRing.CurrentKeyId;

            return(current + ":" + _encryptor.Protect(current, data));
        }
예제 #4
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);
        }