Пример #1
0
        public bool LoginDecryptionAndValidation(string username, string password)
        {
            FileInfo      fileInfo      = new FileInfo("F:/SAUGUMO TEST CHAMBER4/PasswordSystemFiles/AccountList.txt.aes");
            AesEcnryption aesEcnryption = new AesEcnryption();

            if (File.Exists("F:/SAUGUMO TEST CHAMBER4/PasswordSystemFiles/AccountList.txt.aes"))
            {
                aesEcnryption.FileDecryption(fileInfo);
                List <LoginValidationConstructcs> validationConstructcs = new List <LoginValidationConstructcs>();
                foreach (string line in File.ReadAllLines(fileInfo.FullName.Replace(".aes", "")))
                {
                    string[] array = line.Split(',');
                    validationConstructcs.Add(new LoginValidationConstructcs(array[0], array[1]));
                }
                foreach (LoginValidationConstructcs loginValidationConstructcs in validationConstructcs)
                {
                    if (loginValidationConstructcs.username.Equals(username))
                    {
                        Argon2 argon2       = new Argon2();
                        string encryptedPSW = aesEcnryption.PasswordEncryption(password);
                        string inputHash    = argon2.Argon2Impl(encryptedPSW);
                        if (inputHash.Equals(loginValidationConstructcs.hashValue, StringComparison.Ordinal))
                        {
                            FileInfo accountList = new FileInfo(fileInfo.FullName.Replace(".aes", ""));
                            aesEcnryption.FileEncryption(accountList);
                            MessageBox.Show("Login Succesfull");
                            return(true);
                        }
                    }
                }
            }

            MessageBox.Show("Wrong password provided");
            FileInfo decryptedFile = new FileInfo(fileInfo.FullName.Replace(".aes", ""));

            aesEcnryption.FileEncryption(decryptedFile);
            return(false);
        }