forked from mattbuhagiar/SOFT130
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordPrompt.cs
145 lines (121 loc) · 4.07 KB
/
passwordPrompt.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
namespace SOFT130Project
{
public partial class frmPasswordPrompt : Form
{
public frmPasswordPrompt(file this_fileClass)
{
InitializeComponent();
fileClass = this_fileClass;
}
file fileClass;
char char1;
char char2;
char char3;
public void firstPasswordValidate(object sender, EventArgs e)
{
if (txt1stChar.Text.Length == 1)
{
txt2ndChar.Focus();
}
}
public void secondPasswordValidate(object sender, EventArgs e)
{
if (txt2ndChar.Text.Length == 1)
{
txt3rdChar.Focus();
}
}
public void thirdPasswordValidate(object sender, EventArgs e)
{
if (txt3rdChar.Text.Length == 1)
{
}
}
private void frmPasswordPrompt_Load(object sender, EventArgs e)
{
generateVerification();
tmrDateTime_Tick(sender, e);
}
private void generateVerification()
{
int currentCustomerNum = fileClass.getcurrentCustomerNum();
ArrayList returnedData = fileClass.readFile();
Customer thisCustomer = (Customer)returnedData[currentCustomerNum];
txt1stChar.Text = "";
txt2ndChar.Text = "";
txt3rdChar.Text = "";
string password = thisCustomer.getpassword();
float passwordLen = password.Length;
int char1s = 1;
int char1f = Convert.ToInt32(Math.Floor(passwordLen / 3f));
int char2s = char1f + 1;
int char2f = char2s + char1f;
int char3s = char2f + 1;
int char3f = Convert.ToInt32(passwordLen);
Random random = new Random();
int randomNum = random.Next(char1s, char1f + 1);
lbl1stChar.Text = "#" + randomNum;
char1 = password[randomNum - 1];
randomNum = random.Next(char2s, char2f + 1);
lbl2ndChar.Text = "#" + randomNum;
char2 = password[randomNum - 1];
randomNum = random.Next(char3s, char3f + 1);
lbl3rdChar.Text = "#" + randomNum;
char3 = password[randomNum - 1];
txt1stChar.Focus();
}
private void btnVerify_Click(object sender, EventArgs e)
{
verifyPassword();
}
private void verifyPassword()
{
if (Convert.ToString(char1) == txt1stChar.Text &&
Convert.ToString(char2) == txt2ndChar.Text &&
Convert.ToString(char3) == txt3rdChar.Text)
{
frmCustomerView frmCustomerView = new frmCustomerView(fileClass);
frmCustomerView.Show();
this.Close();
}
else
{
generateVerification();
lblFeedback.Text = "The data entered was incorrect.";
MessageBox.Show("WRONG. "
+ char1 + "," + char2 + "," + char3);
}
}
private void txt3rdChar_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
e.SuppressKeyPress = true;
verifyPassword();
}
}
private void btnSkip_Click(object sender, EventArgs e)
{
frmCustomerView frmCustomerView = new frmCustomerView(fileClass);
frmCustomerView.Show();
this.Close();
}
private void tmrDateTime_Tick(object sender, EventArgs e)
{
DateTime CurrTime = DateTime.Now;
lblDate.Text = CurrTime.ToString("D");
lblTime.Text = CurrTime.ToString("hh:mm:ss tt", CultureInfo.CreateSpecificCulture("en-US"));
}
}
}