コード例 #1
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            if (Context == null)
            {
                byte[] key = null;
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    AuthStorage authStorage = AuthStorage.deserialize(Program.passwd_path);
                    key = authStorage.getDBKey(LoginBox.Text.Trim().ToLower(), PasswordBox.Text.Trim().ToLower());
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                    Console.WriteLine(exc.StackTrace);
                }
                if (key == null)
                {
#if DEBUG
                    Console.WriteLine("Неправильний логiн або пароль");
#endif
                    status.ForeColor = Color.Red;
                    status.Text      = "Wrong password or login.";
                }
                Context = new SecureSQLiteContext(Program.db_path, LoginBox.Text.Trim().ToLower(), key);
                Context.Load().Wait();
                Cursor.Current = Cursors.Default;
                DialogResult   = DialogResult.OK;
                Close();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: gregshevchenko3/Balance
        static void Main()
        {
#if DEBUG
            AllocConsole();
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            db_path     = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "data.sqlite");
            passwd_path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "passwd.json");

            object task = new Task <byte[]>(() => new byte[100]);
            Console.WriteLine((task.GetType() == typeof(Task <byte[]>)));
#if DEBUG
            Console.WriteLine(Path.GetTempPath());
#endif
            Task <SecureSQLiteContext> ctx;
            if (!File.Exists(db_path) || !File.Exists(passwd_path))
            {
                ctx = SecureSQLiteContext.FirstRun(db_path);
                AuthStorage       storage = new AuthStorage();
                CreateNewUserForm newform = new CreateNewUserForm(ctx, storage);
                if (newform.ShowDialog() == DialogResult.OK)
                {
                    storage.serialize(passwd_path);
                    Run(ctx.Result);
                    storage.serialize(passwd_path);
                }
                else
                {
                    Task tsk = ctx.Result.Unload();
                    tsk.Wait();
                    if (File.Exists(db_path))
                    {
                        File.Delete(db_path);
                    }
                    if (File.Exists(passwd_path))
                    {
                        File.Delete(passwd_path);
                    }
                }
            }
            else
            {
                Run();
            }
        }
コード例 #3
0
 public CreateNewUserForm(object ctx, AuthStorage auth)
 {
     InitializeComponent();
     _authData = auth;
     _ctx      = ctx;
 }