Beispiel #1
0
        public Users ToData()
        {
            var map = new MapData
            {
                Gpsn    = this.Gpsn,
                Gpsw    = this.Gpsw,
                Address = this.Address,
                City    = this.City,
                State   = this.State
            };

            string[] hashAndSalt = BCryptHash.HashPassword(this.Password);
            return(new Users
            {
                UserName = this.UserName,
                Password = hashAndSalt[0],
                Salt = hashAndSalt[1],
                Fname = this.Fname,
                Lname = this.Lname,
                Phone = this.Phone,
                Email = this.Email,
                IsAdmin = this.IsAdmin,
                LocNavigation = map
            });
        }
Beispiel #2
0
        public void ComputeHashCreatesHashOfSomeInputDataAndItIs256BitsInLength()
        {
            var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            ISecureHash hash       = new BCryptHash();
            var         hashedData = hash.ComputeHash(data);

            Assert.AreEqual(60, hashedData.Length);
        }
Beispiel #3
0
        public void ComputeHashCreatesHashOfSomeInputDataAndItIsDifferentToInputData()
        {
            var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            ISecureHash hash       = new BCryptHash();
            var         hashedData = hash.ComputeHash(data);

            Assert.IsTrue(ByteArrayCompare(data, hashedData));
        }
Beispiel #4
0
        public void ComputeHashCreatesHashOfSomeInputData()
        {
            var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            ISecureHash hash = new BCryptHash();

            byte[] hashedData = hash.ComputeHash(data);

            Assert.IsNotNull(hashedData);
        }
        public async Task CheckHashFailTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            // Act
            bool matches = await handler.CheckHashAsync(sample, failHash);

            // Assert
            Assert.IsFalse(matches);
        }
        public async Task CheckFileHashAsyncTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            // Act
            bool matches = await handler.CheckFileHashAsync(filename, fileHash);

            // Assert
            Assert.IsTrue(matches);
        }
        public async Task GetHashAsyncTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            // Act
            string hash = await handler.GetHashAsync(sample);

            // Assert
            Assert.IsTrue(hash.Length > 0);
        }
Beispiel #8
0
        public Document(IPassword password)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            _aes = new Aes();
            SecureHashProvider  = new BCryptHash();
            _password           = password;
            _fileProxy          = new FileProxy();
            CompressionProvider = new GZipCompression();
        }
        public async Task CheckHashFailStreamTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(sample));

            // Act
            bool matches = await handler.CheckHashAsync(stream, failHash);

            // Assert
            Assert.IsFalse(matches);
        }
        public async Task GetHashAsyncStreamTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(sample));

            // Act
            string hash = await handler.GetHashAsync(stream);

            // Assert
            Assert.IsTrue(hash.Length > 0);
        }
        public async Task GetAndCheckHashTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            // Act
            string hash = await handler.GetHashAsync(sample);

            bool matches = await handler.CheckHashAsync(sample, hash);

            // Assert
            Assert.IsTrue(matches);
        }
        public async Task GetAndCheckHashStreamTest()
        {
            // Arrange
            var handler = new BCryptHash(workFactor);

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(sample));

            // Act
            string hash = await handler.GetHashAsync(stream);

            stream.Position = 0;
            bool matches = await handler.CheckHashAsync(stream, hash);

            // Assert
            Assert.IsTrue(matches);
        }
Beispiel #13
0
        public Password(string password1, string password2)
        {
            if (string.IsNullOrEmpty(password1))
            {
                throw new ArgumentNullException(nameof(password1));
            }

            var optionalPassword2 = password2 ?? string.Empty;

            Password1 = new SecureHash().ComputeHash(Encoding.ASCII.GetBytes(password1));
            Password2 = new SecureHash().ComputeHash(Encoding.ASCII.GetBytes(optionalPassword2));

            BCryptPassword1 = new BCryptHash().ComputeHash(Encoding.ASCII.GetBytes(password1));
            BCryptPassword2 = new BCryptHash().ComputeHash(Encoding.ASCII.GetBytes(optionalPassword2));

            CombinedPasswords = new BCryptHash().ComputeHash(Encoding.ASCII.GetBytes(password1 + optionalPassword2));
        }
Beispiel #14
0
        public async Task <ActionResult <IEnumerable <UsersView> > > GetActionUserName([FromServices] IGet get)
        {
            string[] authorization = await HeaderDecode.DecodeHeader(Request);

            string token = authorization[0], pwd = authorization[1];

            log.LogInformation($"Querrying the database for a user with the username {token}");
            var users = await get.Users(item => item.UserName.Trim() == token);

            if (BCryptHash.VerifyUser(users, pwd))
            {
                return(new ActionResult <IEnumerable <UsersView> >(users));
            }
            else
            {
                return(new ObjectResult("ERROR: Invalid username/password")
                {
                    StatusCode = 400
                });
            }
        }
Beispiel #15
0
        public void ComputeHashThrowsArgumentNullExceptionIfDataToHashedIsNull()
        {
            ISecureHash hash = new BCryptHash();

            hash.ComputeHash(null);
        }