Esempio n. 1
0
        static void ChangePassword()
        {
            Console.WriteLine("Input old master password");
            Cryptography cryptography = new Cryptography();
            string       input        = Console.ReadLine();

            if (!cryptography.CreateHash($"Ich bin {input}, der große König. - Und ich Diogenes, der Hund.").SequenceEqual(_checkHash))
            {
                Console.WriteLine("Wrong Password");
                return;
            }

            IO io = new IO();

            Console.WriteLine("Input new master password");
            string newPassword = Console.ReadLine();

            io.WriteBytes(cryptography.CreateHash($"Ich bin {newPassword}, der große König. - Und ich Diogenes, der Hund."), _checkHashPath);


            byte[] oldKey = cryptography.CreateHash(input);
            byte[] newKey = cryptography.CreateHash(newPassword);


            if (File.Exists(_passwordPath))
            {
                string content = io.ReadEncrypted(_passwordPath, oldKey);
                io.Write(cryptography.Encrypt(content, newKey), _passwordPath, true);
            }
            _checkHash = io.ReadBytes(_checkHashPath);
            Console.WriteLine("Master password set");
        }
Esempio n. 2
0
        static void LoadPassword(string userNameOrWebsite)
        {
            Console.WriteLine("Input master password");
            Cryptography cryptography = new Cryptography();
            string       input        = Console.ReadLine();

            if (!cryptography.CreateHash($"Ich bin {input}, der große König. - Und ich Diogenes, der Hund.").SequenceEqual(_checkHash))
            {
                Console.WriteLine("Wrong Password");
                return;
            }

            PasswordReplacer pr1 = new PasswordReplacer();

            if (input != null)
            {
                pr1.ReplacePassword(Console.CursorTop - 1, 0, 0, input.Length);

                IO     io   = new IO();
                string text = io.ReadEncrypted(_passwordPath, cryptography.CreateHash(input));
                text.Remove(text.Length - 1);
                string[] textArray = text.Split(" ");

                foreach (var t in textArray)
                {
                    if (t.Length > 0)
                    {
                        string s        = t;
                        string password = s.Split("-")[0];
                        string userName = s.Split("-")[1];
                        string website  = s.Split("-")[2];

                        if (userName == userNameOrWebsite || website == userNameOrWebsite)
                        {
                            PasswordReplacer pr2 = new PasswordReplacer();
                            Console.WriteLine($"Website: \"{website}\", Password: \"{password}\"");

                            pr2.ReplacePassword(Console.CursorTop - 1, website.Length + 2, 10000, password.Length);
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        static void Main()
        {
            Directory.CreateDirectory($"C:\\Users\\{Environment.UserName}\\AppData\\Roaming\\PasswordManager");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.BackgroundColor = ConsoleColor.Black;

            Cryptography cryptography = new Cryptography();
            IO           io           = new IO();

            _checkHashPath = $"C:\\Users\\{Environment.UserName}\\AppData\\Roaming\\PasswordManager\\checkhash";
            if (!File.Exists(_checkHashPath))
            {
                Console.WriteLine("Enter master password!");
                io.WriteBytes(cryptography.CreateHash($"Ich bin {Console.ReadLine()}, der große König. - Und ich Diogenes, der Hund."), _checkHashPath);
                Console.WriteLine("Master password set");
                Console.Clear();
            }

            _checkHash = io.ReadBytes(_checkHashPath);

            _passwordPath = $"C:\\Users\\{Environment.UserName}\\AppData\\Roaming\\PasswordManager\\password";

            _load_all       = new Command("load_all", "Loads all passwords", "load_password", LoadAllPasswords);
            _changePassword = new Command("change_password", "Change master password", "change_password",
                                          ChangePassword);
            _checkPassword    = new Command <string>("check_password", "Checks if a password is safe", "check_password <password>", CheckPassword);
            _generatePassword = new Command <int>("generate_password", "Generates password with the given length", "generate_password <password_length>",
                                                  CreatePassword);
            _loadPassword = new Command <string>("load_password", "Load specific password based on user name or website",
                                                 "load_password <username or website>", LoadPassword);
            _savePassword = new Command <string, string, string>("save_password", "Save password with username",
                                                                 "save_password <password>, <username>", SavePassword);
            _help = new Command("help", "Shows all possible commands", "help",
                                ShowHelp);


            _commandList = new List <object>
            {
                _load_all,
                _changePassword,
                _generatePassword,
                _loadPassword,
                _savePassword,
                _help,
                _checkPassword
            };

            while (true)
            {
                _input = Console.ReadLine();
                HandleInput();
            }
        }
Esempio n. 4
0
        static void SavePassword(string password, string userName, string website)
        {
            Console.WriteLine("Saving...");
            Console.WriteLine("Input master password");
            Cryptography cryptography = new Cryptography();
            string       input        = Console.ReadLine();

            if (!cryptography.CreateHash($"Ich bin {input}, der große König. - Und ich Diogenes, der Hund.").SequenceEqual(_checkHash))
            {
                Console.WriteLine("Wrong Password");
                return;
            }
            Console.SetCursorPosition(0, Console.CursorTop - 1);
            if (input != null)
            {
                Console.WriteLine(new string('*', input.Length));

                IO io = new IO();

                io.WriteEncrypted(password + "-" + userName + "-" + website, _passwordPath,
                                  cryptography.CreateHash(input));
            }
        }