-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
75 lines (66 loc) · 2.29 KB
/
Copy pathForm1.cs
File metadata and controls
75 lines (66 loc) · 2.29 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
65
66
67
68
69
70
71
72
73
74
75
using System.Configuration;
namespace project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox2.PasswordChar = '*';
myFile = new FileStream(myFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
myStreamReader = new StreamReader(myFile);
}
public static FileStream myFile;
public static StreamReader myStreamReader;
string myFileName = "userData.txt";
public StreamReader GetStreamReader()
{
return myStreamReader;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void boo_Click(object sender, EventArgs e)
{
myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin);
long startPosition = 0;
string record;
string[] fields;
bool userFound = false;
startPosition = myStreamReader.BaseStream.Position;
while ((record = myStreamReader.ReadLine()) != null)
{
fields = record.Split(",");
// Check if username and password match
if (textBox1.Text == fields[2] && textBox2.Text == fields[3])
{
userFound = true;
startPosition = myStreamReader.BaseStream.Position - record.Length - 2; // Adjust for line terminator
break;
}
startPosition = myStreamReader.BaseStream.Position;
}
if (userFound)
{
fields = record.Split(",");
admin admin = new admin();
admin.FirstName = fields[0];
admin.LastName = fields[1];
admin.StartPosition = startPosition;
admin.Show();
this.Hide();
}
else
{
MessageBox.Show("Wrong User Name or password");
}
}
private void button1_Click(object sender, EventArgs e)
{
myFile.Close();
signIn signIn = new signIn();
signIn.Show();
this.Hide();
}
}
}