static void Run(SecureSQLiteContext ctx = null) { LoginForm loginForm = new LoginForm(ctx); if (loginForm.ShowDialog() == DialogResult.OK) { #if DEBUG Console.WriteLine("Автентифiкацiя успiшна!"); #endif MessageBox.Show("Автентифiкацiя успiшна!"); } else { #if DEBUG Console.WriteLine("Автентифiкацiю вiдмiнив користувач"); #endif MessageBox.Show("Автентифiкацiю вiдмiнив користувач"); try { loginForm.Context.Unload().Wait(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.InnerException.StackTrace); Console.ReadLine(); } } }
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(); } }
public new static async Task <SecureSQLiteContext> FirstRun(string db_name) { SecureSQLiteContext ctx = new SecureSQLiteContext(db_name); await FirstRun(ctx, db_name); ctx.load_user(); return(ctx); }
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(); } }
private void RegisterBtn_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; SecureSQLiteContext ctx = WaitIfTask <SecureSQLiteContext>(_ctx); this.Cursor = Cursors.Default; if (PasswordBox1.Text.Trim() != PasswordBox2.Text.Trim()) { status.ForeColor = Color.Red; status.Text = $"Введенi паролi не спiвпадаютью"; } else if (!_authData.check_quality(PasswordBox1.Text.Trim())) { status.ForeColor = Color.Red; status.Text = "Пароль недостатньо надiйний"; } else if (ctx.SetDefaultUserRights(LoginBox.Text)) { status.ForeColor = Color.Green; status.Text = "Користувача добавлено, права - надано"; var sb = new StringBuilder(ctx.Key.Length * 2); foreach (byte b in ctx.Key) { sb.Append(b.ToString("x2")); } _authData.appendUser(LoginBox.Text.Trim().ToLower(), PasswordBox1.Text.Trim().ToLower(), sb.ToString()); DialogResult = DialogResult.OK; Close(); } else { status.ForeColor = Color.Red; status.Text = $"Користувач '{LoginBox.Text}' iснує."; } }
public LoginForm(SecureSQLiteContext ctx = null) { InitializeComponent(); Context = ctx; }