Example #1
0
        /// <summary>
        /// Decrypts vault data.
        /// </summary>
        /// <returns></returns>
        private static string DecryptData()
        {
            Console.WriteLine("Enter vault name:");
            string vault = Console.ReadLine();

            vault = vault.ToLower();
            while (!CheckVaultExist(vault))
            {
                if (CheckMaxTries())
                {
                    return(string.Empty);
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Vault does not exist!");
                Console.WriteLine("Enter vault name:");
                vault = Console.ReadLine();
            }
            s_tries = 0;
            string encryptedData = File.ReadAllText(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x");

            WordColorInLine("Enter master password for ", vault, " vault:", ConsoleColor.Cyan);
            string masterPassword = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());

            Console.WriteLine();
            string decryptVault = Core.Encryption.AES.Decrypt(encryptedData, masterPassword);

            return(decryptVault);
        }
Example #2
0
        public void Execute(string arg)
        {
            Console.WriteLine("*******************************************");
            Console.WriteLine("**********Email Sender Client**************");
            Console.WriteLine("*******************************************");
            Console.WriteLine(" ");
            //difine the email parameters
            Console.WriteLine("** Enter your eMail address **");
            s_mailFrom = Console.ReadLine();
            Console.WriteLine("** Enter your eMail Name (default blank) **");
            if (String.IsNullOrWhiteSpace(s_mailName = Console.ReadLine()))
            {
                s_mailName = "";
            }
            Console.WriteLine("** Enter your eMail password **");
            s_mailPass = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());
            Console.WriteLine();
            Console.WriteLine("** Enter destination eMail address **");
            s_mailTo = Console.ReadLine();
            Console.WriteLine("** Enter eMail title **");
            s_mailTitle = Console.ReadLine();
            Console.WriteLine("** Enter eMail body content **");
            s_mailBody = Console.ReadLine();
            //-----------------------------------


            //sending the mail
            try
            {
                eMailS.MailSend(s_mailFrom, s_mailName, s_mailPass, s_mailTo, s_mailTitle, s_mailBody);
            }
            catch (Exception e)
            {
                FileSystem.ErrorWriteLine(e.ToString());
            }
            //----------------------
        }
Example #3
0
        /// <summary>
        /// Update account's password from an application.
        /// </summary>
        private static void UpdateAppUserData()
        {
            List <string> listApps     = new List <string>();
            bool          accountCheck = false;

            Console.WriteLine("Enter vault name:");
            string vault = Console.ReadLine();

            vault = vault.ToLower();
            while (!CheckVaultExist(vault))
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Vault does not exist!");
                Console.WriteLine("Enter vault name:");
                vault = Console.ReadLine();
            }
            s_tries = 0;
            string encryptedData = File.ReadAllText(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x");

            WordColorInLine("Enter master password for ", vault, " vault:", ConsoleColor.Cyan);
            string masterPassword = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());

            Console.WriteLine();
            string decryptVault = Core.Encryption.AES.Decrypt(encryptedData, masterPassword);

            if (decryptVault.Contains("Error decrypting"))
            {
                FileSystem.ErrorWriteLine("Something went wrong. Check master password or vault name!");
                return;
            }
            Console.WriteLine("Enter application name:");
            string application = Console.ReadLine();

            while (string.IsNullOrEmpty(application))
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Application name should not be empty!");
                Console.WriteLine("Enter application name:");
                application = Console.ReadLine();
            }
            s_tries = 0;
            while (!decryptVault.Contains(application))
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Application {application} does not exist!");
                Console.WriteLine("Enter application name:");
                application = Console.ReadLine();
            }
            s_tries = 0;
            WordColorInLine("Enter account name for ", application, ":", ConsoleColor.Magenta);
            string accountName = Console.ReadLine();

            while (string.IsNullOrEmpty(accountName))
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Account name should not be empty!");
                WordColorInLine("Enter account name for ", application, ":", ConsoleColor.Magenta);
                accountName = Console.ReadLine();
            }
            s_tries = 0;
            WordColorInLine("Enter new password for ", accountName, ":", ConsoleColor.Green);
            string password = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());

            Console.WriteLine();
            using (var reader = new StringReader(decryptVault))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    s_serializer = new JavaScriptSerializer();
                    if (line.Length > 0)
                    {
                        var outJson = s_serializer.Deserialize <Dictionary <string, string> >(line);
                        if (outJson["site/application"] == application && outJson["account"] == accountName)
                        {
                            var keyValues = new Dictionary <string, object>
                            {
                                { "site/application", application },
                                { "account", accountName },
                                { "password", password },
                            };
                            accountCheck = true;
                            listApps.Add(s_serializer.Serialize(keyValues));
                        }
                        else
                        {
                            listApps.Add(line);
                        }
                    }
                }
                string encryptdata = Core.Encryption.AES.Encrypt(string.Join("\n", listApps), masterPassword);
                listApps.Clear();
                if (File.Exists(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x"))
                {
                    if (accountCheck)
                    {
                        File.WriteAllText(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x", encryptdata);
                        WordColorInLine("\n[*]Password for ", accountName, " was updated!\n", ConsoleColor.Green);
                        return;
                    }
                    FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Account {accountName} does not exist!");
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Vault {vault} does not exist!");
            }
        }
Example #4
0
        /// <summary>
        /// Add new application to a current vault.
        /// </summary>
        private static void AddPasswords()
        {
            Console.WriteLine("Enter vault name:");
            string vault = Console.ReadLine();

            vault = vault.ToLower();
            while (!CheckVaultExist(vault))
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Vault does not exist!");
                Console.WriteLine("Enter vault name:");
                vault = Console.ReadLine();
            }
            s_tries = 0;
            string encryptedData = File.ReadAllText(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x");

            WordColorInLine("Enter master password for ", vault, " vault:", ConsoleColor.Cyan);
            string masterPassword = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());

            Console.WriteLine();
            string decryptVault = Core.Encryption.AES.Decrypt(encryptedData, masterPassword);

            if (decryptVault.Contains("Error decrypting"))
            {
                FileSystem.ErrorWriteLine("Something went wrong. Check master password or vault name!");
                return;
            }
            Console.WriteLine("Enter application name:");
            string application = Console.ReadLine();

            while (application.Length < 3)
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "The length of application name should be at least 3 characters!");
                Console.WriteLine("Enter application name:");
                application = Console.ReadLine();
            }
            s_tries = 0;
            WordColorInLine("Enter account name for ", application, ":", ConsoleColor.Magenta);
            string account = Console.ReadLine();

            while (account.Length < 3)
            {
                if (CheckMaxTries())
                {
                    return;
                }
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "The length of account name should be at least 3 characters!");
                WordColorInLine("Enter account name for ", application, ":", ConsoleColor.Magenta);
                account = Console.ReadLine();
            }
            s_tries = 0;
            using (var reader = new StringReader(decryptVault))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    s_serializer = new JavaScriptSerializer();
                    var outJson = s_serializer.Deserialize <Dictionary <string, string> >(line);
                    if (line.Length > 0)
                    {
                        if (outJson["site/application"] == application && outJson["account"] == account)
                        {
                            FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Vault already contains {account} account in {application} application!");
                            return;
                        }
                    }
                }
            }

            WordColorInLine("Enter password for ", account, ":", ConsoleColor.Green);
            string password = PasswordValidator.ConvertSecureStringToString(PasswordValidator.GetHiddenConsoleInput());

            Console.WriteLine();
            var keyValues = new Dictionary <string, object>
            {
                { "site/application", application },
                { "account", account },
                { "password", password },
            };

            s_serializer = new JavaScriptSerializer();
            string encryptdata = Core.Encryption.AES.Encrypt(decryptVault + "\n" + s_serializer.Serialize(keyValues), masterPassword);

            if (File.Exists(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x"))
            {
                File.WriteAllText(GlobalVariables.passwordManagerDirectory + $"\\{vault}.x", encryptdata);
                WordColorInLine("\n[+] Data for ", application, " is encrypted and added to vault!\n", ConsoleColor.Magenta);
                return;
            }
            else
            {
                FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Vault {vault} does not exist!");
            }
        }
Example #5
0
        /// <summary>
        /// Creates a new vault.
        /// </summary>
        private static void CreateVault()
        {
            string vaultName;
            string masterPassword1;
            string masterPassword2;
            bool   userNameIsValid = false;
            bool   passValidation  = false;

            do
            {
                Console.WriteLine("Vault Name: ");
                vaultName = Console.ReadLine();
                vaultName = vaultName.ToLower();
                var vaultFiles = Directory.GetFiles(GlobalVariables.passwordManagerDirectory);
                if (vaultName.Length < 3)
                {
                    FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Vault name must be at least 3 characters long!");
                }
                else if (string.Join("\n", vaultFiles).Contains($"{vaultName}.x"))
                {
                    FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, $"Vault {vaultName} already exist!");
                }
                else
                {
                    userNameIsValid = true;
                }
                if (CheckMaxTries())
                {
                    return;
                }
            } while (userNameIsValid == false);
            s_tries = 0;
            do
            {
                Console.WriteLine("Master Password: "******"Confirm Master Password: "******"Passwords are not the same!");
                }
                else
                {
                    passValidation = true;
                }
                if (!PasswordValidator.ValidatePassword(masterPassword2))
                {
                    FileSystem.ColorConsoleTextLine(ConsoleColor.Yellow, "Password must be at least 12 characters, and must include at least one upper case letter, one lower case letter, one numeric digit, one special character and no space!");
                }
                if (CheckMaxTries())
                {
                    return;
                }
            } while ((masterPassword1 != masterPassword2) || !PasswordValidator.ValidatePassword(masterPassword2));
            s_tries = 0;
            if (passValidation)
            {
                string sealVault = Core.Encryption.AES.Encrypt(string.Empty, masterPassword1);
                if (!sealVault.Contains("Error encrypting"))
                {
                    File.WriteAllText(GlobalVariables.passwordManagerDirectory + $"\\{vaultName}.x", sealVault);
                    WordColorInLine("\n[+] Vault ", vaultName, " was created!\n", ConsoleColor.Cyan);
                    return;
                }
                FileSystem.ErrorWriteLine(sealVault + ". Check command!");
            }
        }