-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm4.cs
More file actions
64 lines (54 loc) · 1.82 KB
/
Copy pathForm4.cs
File metadata and controls
64 lines (54 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SharpPhone
{
public partial class Start : Form
{
private int wrongs = 0;
public Start()
{
InitializeComponent();
JsonStore.Load();
}
private void btnLogin_Click(object sender, EventArgs e)
{
var username = txtUser.Text ?? string.Empty;
var password = txtPass.Text ?? string.Empty;
var user = SharpPhoneDataBase.userAccounts.FirstOrDefault(u => u.username.Equals(username, StringComparison.OrdinalIgnoreCase));
if (user == null)
{
MessageBox.Show("No user", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (user.locked)
{
MessageBox.Show("This account is locked due to too many failed login attempts.", "Account Locked", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (user.password == password)
{
user.failedAttempts = 0;
JsonStore.Save();
MainPage mainPage = new MainPage();
mainPage.Show();
Close();
return;
}
user.failedAttempts++;
if (user.failedAttempts >= 3)
{
user.locked = true;
}
JsonStore.Save();
MessageBox.Show("Wrong Username or Password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (user.failedAttempts >= 3) System.Windows.Forms.Application.Exit();
}
}
}