예제 #1
0
파일: Seeder.cs 프로젝트: FilipJQ77/IO
        protected void UserSeeder()
        {
            var userRep = new RepositoryFactory().GetRepository <User>();
            var hasher  = new HasherFactory().GetHasher();

            userRep.Add(new User
            {
                Login    = "******",
                Password = hasher.Hash("haslo1234"),
                Rank     = Rank.Student,
            });

            userRep.Add(new User
            {
                Login    = "******",
                Password = hasher.Hash("haslo1234"),
                Rank     = Rank.Student,
            });

            userRep.Add(new User
            {
                Login    = "******",
                Password = hasher.Hash("haslo1234"),
                Rank     = Rank.Administrator,
            });

            userRep.SaveChanges();
        }
예제 #2
0
        static void Main(string[] args)
        {
            //System.Console.WriteLine("Hello World!");

            //var path = @"E:\FileClientAPI\2\myDoc.ApiClient.dll";

            //var factory = HasherFactory.CreateHasher(path);

            //var md5 = factory.GetHash(path);

            //System.Console.WriteLine(md5);

            var path = @"E:\test\AssemblyHasher.Core.dll";

            //factory = HasherFactory.CreateHasher(path);

            //md5 = factory.GetHash(path);

            //System.Console.WriteLine(md5);

            var md5 = HasherFactory.GetHash(path);

            System.Console.WriteLine(md5);

            var md5default = HasherFactory.GetHash(path, HasherEnum.Default);

            System.Console.WriteLine(md5default);

            var md5lhasher = HasherFactory.GetHash(path, HasherEnum.IlHasher);

            System.Console.WriteLine(md5lhasher);

            System.Console.ReadKey();
        }
예제 #3
0
        public void creates_default_hasher_for_win32_exe()
        {
            // arrange

            // act
            var hasher = HasherFactory.CreateHasher(@"..\..\Samples\Win32Identical.build1\win32example.exe");

            // assert
            Assert.IsAssignableFrom <DefaultHasher>(hasher);
        }
예제 #4
0
        public void creates_il_hasher_for_cli_exe()
        {
            // arrange

            // act
            var hasher = HasherFactory.CreateHasher(@"..\..\Samples\CliIdentical.build1\asmcomp.exe");

            // assert
            Assert.IsAssignableFrom <IlHasher>(hasher);
        }
예제 #5
0
        public void Should_Return_False_If_Passed_String_That_Does_Not_Equal_Existing_Password()
        {
            // arrange
            var passwordPlainText = "p@$$w0rd1";
            var hasherFactory     = new HasherFactory(new HashSettings(100, 32, 32, HashAlgorithm.PBKDF2));
            var hasher            = hasherFactory.Create();
            var password          = hasher.CreatePassword(passwordPlainText);
            var passwordService   = new PasswordService(hasherFactory);

            // act
            var result = passwordService.IsPasswordValid($"{passwordPlainText}1", password);

            // assert
            result.ShouldBeFalse();
        }
예제 #6
0
        // we finalize the ledger and create a new immutable ledger state
        private void Finalize(SignedLedger signed, LedgerPostState state)
        {
            var ledgerState = state.Finalize(HasherFactory.CreateHasher(signed.GetVersion()));

            if (!CheckMerkleRoot(ledgerState, signed))
            {
                throw new Exception("Merkle root is not valid");
            }

            LiveService.PersistenceManager.Save(new SignedLedgerState(signed, state.GetLedgerStateChange()));

            LedgerState = ledgerState;
            LastLedger  = signed;

            OnNewLedger(LastLedger);
        }
예제 #7
0
        public (bool, string) LogIn(Dictionary <string, string> data)
        {
            if (!data.ContainsKey("login"))
            {
                return(false, "Należy podać login");
            }
            if (!data.ContainsKey("password"))
            {
                return(false, "Należy podać hasło");
            }

            string login    = data["login"];
            string password = data["password"];

            var userRep = new RepositoryFactory().GetRepository <User>();
            var user    = userRep.GetDetail(p => p.Login == login);

            if (user == null)
            {
                return(false, "Podany użytkownik nie istnieje");
            }

            var hasher = new HasherFactory().GetHasher();

            if (!hasher.Check(user.Password, password))
            {
                return(false, "Nieprawidłowe hasło");
            }

            IUser loginUser;

            if (user.Rank == Rank.Student)
            {
                var sdRep = new RepositoryFactory().GetRepository <StudentData>();
                var sd    = sdRep.GetDetail(p => p.UserId == user.Id);
                loginUser = new UserFactory().CreateStudent(user, sd);
            }
            else
            {
                loginUser = new UserFactory().CreateAdmin(user);
            }

            var(loggedIn, token) = _loggedUsers.LogInUser(loginUser);

            return(loggedIn ? (true, token) : (false, "Użytkownik jest już zalogowany"));
        }
예제 #8
0
        public void Should_Not_Output_New_Password_Hash_If_Settings_Have_Not_Changed()
        {
            // arrange
            var passwordPlainText = "p@$$w0rd1";
            var hasherFactory     = new HasherFactory(new HashSettings(100, 32, 32, HashAlgorithm.PBKDF2));
            var hasher            = hasherFactory.Create();
            var password          = hasher.CreatePassword(passwordPlainText);
            var passwordService   = new PasswordService(hasherFactory);

            // act
            var hash    = String.Empty;
            var isValid = passwordService.IsPasswordValid(passwordPlainText, password, out hash);

            // assert
            hash.ShouldBeNullOrEmpty();
            isValid.ShouldBeTrue();
        }
예제 #9
0
        public void Should_Output_New_Password_Hash_If_Settings_Have_Changed_Since_Original_Was_Generated()
        {
            // arrange
            var passwordPlainText = "p@$$w0rd1";
            var hasherFactory     = new HasherFactory(new HashSettings(100, 32, 32, HashAlgorithm.PBKDF2));
            var hasher            = hasherFactory.Create();
            var password          = hasher.CreatePassword(passwordPlainText);
            var passwordService   = new PasswordService(hasherFactory);

            var hashFactoryWithupdatedSettings = new HasherFactory(new HashSettings(1000, 8, 24, HashAlgorithm.PBKDF2));
            var passwordServiceUpdated         = new PasswordService(hashFactoryWithupdatedSettings);

            // act
            var hash    = String.Empty;
            var isValid = passwordServiceUpdated.IsPasswordValid(passwordPlainText, password, out hash);

            // assert
            hash.ShouldNotBeNullOrEmpty();
            isValid.ShouldBeTrue();
        }
예제 #10
0
        private void InitializeLedger(SignedLedger lastLedger)
        {
            var accounts = new Trie <Account>(Address.RAW_SIZE);

            foreach (var account in LiveService.AccountManager.GetAccounts())
            {
                accounts.CreateOrUpdate(account.Key.ToRawBytes(), old =>
                {
                    if (old != null)
                    {
                        throw new Exception("The ledger's account states are duplicated !");
                    }
                    return(account.Value);
                });
            }
            // TODO compute hash
            accounts.ComputeHash(HasherFactory.CreateHasher(lastLedger.GetVersion()));

            LedgerState = new LedgerStateFinal(accounts);
            LastLedger  = lastLedger;
            // Debug.Assert(SignedLedgerValidator.Validate(this.lastLedger) == LedgerValidationStatus.Ok, "Last Ledger is not valid"); // Most likely not enough signatures (see quorum)
        }
예제 #11
0
        public static LedgerMerkleRootHash GetMerkleRootHash(LedgerStateFinal ledgerState, ProtocolVersion version, ILogger logger)
        {
            // backward compatibility
            if (version == ProtocolVersion.InitialVersion)
            {
                return(new LedgerMerkleRoot(ledgerState.GetAccounts().Where(account => account.Balances.Any()), GetDeclarations(ledgerState), logger, HasherFactory.CreateHasher(version)).Hash);
            }

            return(ledgerState.GetHash());
        }
예제 #12
0
 public LedgerStateFinal Finalize(ProtocolVersion version)
 {
     return(PostState.Finalize(HasherFactory.CreateHasher(version)));
 }
예제 #13
0
        public static KeyValuePair <string, string> Hash(string text, HashType hashType)
        {
            var hasher = HasherFactory.Create(hashType);

            return(hasher.Hash(text));
        }
예제 #14
0
        public static bool CompareHashed(HashType hashType, string hashedCurrent, string plainNew, string salt)
        {
            var hasher = HasherFactory.Create(hashType);

            return(hasher.CompareHashed(hashedCurrent, plainNew, salt));
        }