Exemple #1
0
        // LoadSettings is called from Program.cs
        internal static bool LoadSettings()
        {
            if (!File.Exists(Shared.SettingsFile))
            {
                settings            = new SettingsRoot();
                settings.appTimeout = 1.00M;
                settings.dbServer   = $"database_{Shared.DbUserTableName.DecryptBase64StringToText().ToUnsecureString()}.json";
                settings.dbType     = 0;
                SaveSettings();
                return(false);
            }

            settings = JsonConvert.DeserializeObject <SettingsRoot>(File.ReadAllText(Shared.SettingsFile));
            AbstractDatabase db = Shared.GetDatabase();

            if (db.ConnectionString != "" && db.TestConnection())
            {
                dtCredentials = db.GetPasswords();
            }
            foreach (DataRow dr in dtCredentials.Rows)
            {
                dr["CredentialName"] = dr["CredentialName"].ToString().DecryptBase64StringToText().ToUnsecureString();
            }

            return(true);
        }
Exemple #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            using (LoginForm form = new LoginForm())
            {
                form.Text = "Enter or Create Credentials";
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Shared.DbUserTableName = form.id.EncryptTextToBase64String();
                    Shared.SettingsFile    = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), $"settings_{Shared.DbUserTableName.DecryptBase64StringToText().ToUnsecureString()}.json");

                    if (LoadSettings())
                    {
                        if (settings.appUserID == form.id.ToHash().ToUnsecureString() && settings.appPassword == form.pwd.ToHash().ToUnsecureString())
                        {
                            Application.Run(new Form1());
                        }
                    }
                    else
                    {
                        settings             = new SettingsRoot();
                        settings.appUserID   = form.id.ToHash().ToUnsecureString();
                        settings.appPassword = form.pwd.ToHash().ToUnsecureString();
                        settings.appTimeout  = 1.00M;
                        settings.dbServer    = "database.json".ToSecureString().EncryptTextToBase64String();
                        settings.dbType      = 0;
                        SaveSettings();
                        MessageBox.Show("The Vault has been initialized. You can go into the settings by clicking on the program's icon in the upper-left corner of the window.");
                        Application.Run(new Form1());
                    }
                }
            }
        }