Beispiel #1
0
 public override StoredBlock Get(Sha256Hash hash)
 {
     using (locker.AcquireReaderLock())
     {
         StoredBlock block;
         if (store.TryGetValue(hash.ToString(), out block))
         {
             return(block);
         }
         return(null);
     }
 }
        public async Task <bool> ChangePasswordAsync(int userId, string oldPassword, string newPassword)
        {
            User = await Context.Users.WhereId(userId).SingleOrDefaultAsync();

            Sha256Hash oldPasswordHash = new Sha256Hash(oldPassword, User.Salt);

            if (User.Password != oldPasswordHash.ToString())
            {
                return(false);
            }

            User.Salt               = Guid.NewGuid().ToString("N");
            User.Password           = new Sha256Hash(newPassword, User.Salt).ToString();
            User.LastChangePassword = DateTime.UtcNow;

            await Context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> SignInAsync(string email, string password)
        {
            User = await Context.Users
                   .WhereEmail(email)
                   .SingleOrDefaultAsync();

            if (User != null)
            {
                Sha256Hash passwordHash = new Sha256Hash(password, User.Salt);

                if (User.Password == passwordHash.ToString())
                {
                    User.LastLogin = DateTime.UtcNow;
                    await Context.SaveChangesAsync();

                    return(true);
                }
            }

            return(false);
        }