账号密码的登录程序: Class1 ck=new Class1(); bool
Assert.AreEqual(true,result);
public class Class1
{ private const int MaxNum = 35; private string[] m_Acoount, m_Password; public Class1()
result=ck.Check("2011494011","1");
{ m_Acoount = new string[MaxNum]; result=ck.Check("[1**********]","35");
m_Password = new string[MaxNum];
for (int i = 0; i
m_Acoount[i] = "201149401" + (i + 1).ToString();
m_Password[i] =
(i
+
1).ToString(); }
public bool Check(string account,string password) {
for (int i = 0; i
i++)
{ if ((string.Compare(account,
m_Acoount[i]) == 0)
&& (string.Compare(password, m_Password[i]) == 0))
return true;
else if ((string.Compare(account, m_Acoount[i]) != 0)
&& (string.Compare(password, m_Password[i]) == 0))
return false;
else if ((string.Compare(account, m_Acoount[i]) == 0)
&& (string.Compare(password, m_Password[i]) != 0))
return false; }
return false;
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 上述程序的调试代码:public class TestCheck {[Test] public void TestCheck1() {
// TODO: Add your test.
Assert.AreEqual(true,result);
result=ck.Check("[1**********]","10");
Assert.AreEqual(true,result);
result=ck.Check("[1**********]","36");
Assert.AreEqual(false,result);
result=ck.Check("2011494010","0");
Assert.AreEqual(false,result);
}........................................................................................
注册代码的类代码。。。 class Classcreat : Interfacedenglu {
string file = @"D:\z.txt";
public int zhuce(string account, string password, string s_password,string name) {
FileInfo f1 = new FileInfo(file); FileStream read_zhuce
=
f1.OpenRead(); byte[] datar
=
new
byte[(int)f1.Length];
read_zhuce.Read(datar, 0,
(int)f1.Length); string
value
=
System.Text.Encoding.ASCII.GetString(datar); string[] array = value.Split(' '); read_zhuce.Close(); int i;
for (i = 0; i
StreamWriter write
= f1.AppendText();
write.Write (account + " " + password + " "+name+" "); write.Flush(); write.Close(); return i; } else
return -1; }
public int denglu(string m_account, string m_password) {
FileInfo f2 = new FileInfo(file); FileStream read_denglu
=
f2.OpenRead(); byte[] datar1
=
new
byte[(int)f2.Length];
read_denglu.Read(datar1, 0,
(int)f2.Length); string
read
=
System.Text.Encoding.ASCII.GetString(datar1); string[] array = read.Split(' '); read_denglu.Close();
int i;///0账号错1都对2密码错 for (i = 0; i
return i; else
return -2; return-1;
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
注册界面各控件的代码:
private void button1_Click(object sender, EventArgs e) {
Interfacedenglu creat
=
new Classcreat(); int a
=
creat.zhuce(textBox1 .Text ,textBox2 .Text,textBox3.
Text,textBox4 .Text );
if (textBox1.Text == "" ||
textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{ MessageBox.Show("请填好你的信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Focus(); return; } if (a>=0)
DialogResult = MessageBox.Show("恭喜注册成功请登录","提示",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
if(DialogResult ==
DialogResult .OK )
this.Close (); if(a==-1) DialogResult = MessageBox.Show("输入密码不统一,请确认后再输
入
","
提
示
",MessageBoxButtons .OK ,MessageBoxIcon.Error );
if (DialogResult
== DialogResult.OK)
textBox2.Text =
"";
textBox3.Text = "";
textBox2.Focus(); if (a == -3) DialogResult =
MessageBox.Show("你所输入的账号已存在,请更换账号再进行注册", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Error );
if (DialogResult
==
DialogResult.OK)
textBox1.Text =
""; textBox2.Text = ""; textBox3.Text = ""; textBox1.Focus(); private void
button2_Click(object
sender, EventArgs e) {
DialogResult = MessageBox.Show("确定要退出注册吗?", "提示",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (DialogResult == DialogResult.Yes)
this.Close(); }}}} 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
登录和登录时储存账户密码的文档代码 private
void
btn_denglu_Click(object
sender,
EventArgs e) {
Form form8 = new Form8(this); string file = @"D:\z.txt"; FileInfo f1 = new FileInfo(file); FileStream read_zhuce
= f1.OpenRead(); byte[] datar
=
new byte[(int)f1.Length];
read_zhuce.Read(datar, 0, (int)f1.Length); string
value
=
System.Text.Encoding.ASCII .GetString(datar); string[] array = value.Split(' '); read_zhuce.Close(); if (textBox1.Text
==
""
||
textBox2.Text == "")
{
MessageBox.Show("请输入账号密码",
"提示", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
textBox1.Focus(); return; } int c;
Interfacedenglu dl = new Classcreat(); c =
dl.denglu(textBox1.Text,
textBox2.Text);
if (c == -1)
{ DialogResult = MessageBox.Show("账号不存在,请重新输入","提示",MessageBoxButtons .OK ,MessageBoxIcon.Stop );
if (DialogResult
==
DialogResult.OK)
textBox2.Text = ""; textBox1.Text = "";
textBox1.Focus(); }
else if (c >=0)
{DialogResult =MessageBox.Show("恭喜"+array[c+2]+"成功登录系统", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk ); if (DialogResult
==
DialogResult.OK)
this.Hide();
Form form3 = new Form3(); form3.Show();
form8.Show(); }
else if (c == -2)
{ MessageBox.Show("密码错误,请确认后再次尝试登录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
if (DialogResult
==
DialogResult.OK)
textBox2.Text = ""; textBox2.Focus();
} private void
label3_Click(object
sender,
EventArgs e) {
Form form2 = new Form2(); form2.Show();
} private void Form1_Load(object sender, EventArgs e) {
string file = @"D:\z.txt"; if (File.Exists(file))
MessageBox.Show("你的信息将存
放
在
z.txt
内
","
提
示
",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
else
MessageBox.Show("发现不存在z.txt,将自动帮你新建","提示
",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
FileInfo f2 = new FileInfo(file); StreamWriter write = f2.AppendText();
write.Close(); }
private void btn_tuichu_Click(object sender, EventArgs e) {
DialogResult = MessageBox.Show("确定要退出登录系统吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult == DialogResult.Yes) } } }
this.Close();
账号密码的登录程序: Class1 ck=new Class1(); bool
Assert.AreEqual(true,result);
public class Class1
{ private const int MaxNum = 35; private string[] m_Acoount, m_Password; public Class1()
result=ck.Check("2011494011","1");
{ m_Acoount = new string[MaxNum]; result=ck.Check("[1**********]","35");
m_Password = new string[MaxNum];
for (int i = 0; i
m_Acoount[i] = "201149401" + (i + 1).ToString();
m_Password[i] =
(i
+
1).ToString(); }
public bool Check(string account,string password) {
for (int i = 0; i
i++)
{ if ((string.Compare(account,
m_Acoount[i]) == 0)
&& (string.Compare(password, m_Password[i]) == 0))
return true;
else if ((string.Compare(account, m_Acoount[i]) != 0)
&& (string.Compare(password, m_Password[i]) == 0))
return false;
else if ((string.Compare(account, m_Acoount[i]) == 0)
&& (string.Compare(password, m_Password[i]) != 0))
return false; }
return false;
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 上述程序的调试代码:public class TestCheck {[Test] public void TestCheck1() {
// TODO: Add your test.
Assert.AreEqual(true,result);
result=ck.Check("[1**********]","10");
Assert.AreEqual(true,result);
result=ck.Check("[1**********]","36");
Assert.AreEqual(false,result);
result=ck.Check("2011494010","0");
Assert.AreEqual(false,result);
}........................................................................................
注册代码的类代码。。。 class Classcreat : Interfacedenglu {
string file = @"D:\z.txt";
public int zhuce(string account, string password, string s_password,string name) {
FileInfo f1 = new FileInfo(file); FileStream read_zhuce
=
f1.OpenRead(); byte[] datar
=
new
byte[(int)f1.Length];
read_zhuce.Read(datar, 0,
(int)f1.Length); string
value
=
System.Text.Encoding.ASCII.GetString(datar); string[] array = value.Split(' '); read_zhuce.Close(); int i;
for (i = 0; i
StreamWriter write
= f1.AppendText();
write.Write (account + " " + password + " "+name+" "); write.Flush(); write.Close(); return i; } else
return -1; }
public int denglu(string m_account, string m_password) {
FileInfo f2 = new FileInfo(file); FileStream read_denglu
=
f2.OpenRead(); byte[] datar1
=
new
byte[(int)f2.Length];
read_denglu.Read(datar1, 0,
(int)f2.Length); string
read
=
System.Text.Encoding.ASCII.GetString(datar1); string[] array = read.Split(' '); read_denglu.Close();
int i;///0账号错1都对2密码错 for (i = 0; i
return i; else
return -2; return-1;
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
注册界面各控件的代码:
private void button1_Click(object sender, EventArgs e) {
Interfacedenglu creat
=
new Classcreat(); int a
=
creat.zhuce(textBox1 .Text ,textBox2 .Text,textBox3.
Text,textBox4 .Text );
if (textBox1.Text == "" ||
textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{ MessageBox.Show("请填好你的信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox1.Focus(); return; } if (a>=0)
DialogResult = MessageBox.Show("恭喜注册成功请登录","提示",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
if(DialogResult ==
DialogResult .OK )
this.Close (); if(a==-1) DialogResult = MessageBox.Show("输入密码不统一,请确认后再输
入
","
提
示
",MessageBoxButtons .OK ,MessageBoxIcon.Error );
if (DialogResult
== DialogResult.OK)
textBox2.Text =
"";
textBox3.Text = "";
textBox2.Focus(); if (a == -3) DialogResult =
MessageBox.Show("你所输入的账号已存在,请更换账号再进行注册", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Error );
if (DialogResult
==
DialogResult.OK)
textBox1.Text =
""; textBox2.Text = ""; textBox3.Text = ""; textBox1.Focus(); private void
button2_Click(object
sender, EventArgs e) {
DialogResult = MessageBox.Show("确定要退出注册吗?", "提示",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (DialogResult == DialogResult.Yes)
this.Close(); }}}} 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
登录和登录时储存账户密码的文档代码 private
void
btn_denglu_Click(object
sender,
EventArgs e) {
Form form8 = new Form8(this); string file = @"D:\z.txt"; FileInfo f1 = new FileInfo(file); FileStream read_zhuce
= f1.OpenRead(); byte[] datar
=
new byte[(int)f1.Length];
read_zhuce.Read(datar, 0, (int)f1.Length); string
value
=
System.Text.Encoding.ASCII .GetString(datar); string[] array = value.Split(' '); read_zhuce.Close(); if (textBox1.Text
==
""
||
textBox2.Text == "")
{
MessageBox.Show("请输入账号密码",
"提示", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
textBox1.Focus(); return; } int c;
Interfacedenglu dl = new Classcreat(); c =
dl.denglu(textBox1.Text,
textBox2.Text);
if (c == -1)
{ DialogResult = MessageBox.Show("账号不存在,请重新输入","提示",MessageBoxButtons .OK ,MessageBoxIcon.Stop );
if (DialogResult
==
DialogResult.OK)
textBox2.Text = ""; textBox1.Text = "";
textBox1.Focus(); }
else if (c >=0)
{DialogResult =MessageBox.Show("恭喜"+array[c+2]+"成功登录系统", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk ); if (DialogResult
==
DialogResult.OK)
this.Hide();
Form form3 = new Form3(); form3.Show();
form8.Show(); }
else if (c == -2)
{ MessageBox.Show("密码错误,请确认后再次尝试登录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
if (DialogResult
==
DialogResult.OK)
textBox2.Text = ""; textBox2.Focus();
} private void
label3_Click(object
sender,
EventArgs e) {
Form form2 = new Form2(); form2.Show();
} private void Form1_Load(object sender, EventArgs e) {
string file = @"D:\z.txt"; if (File.Exists(file))
MessageBox.Show("你的信息将存
放
在
z.txt
内
","
提
示
",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
else
MessageBox.Show("发现不存在z.txt,将自动帮你新建","提示
",MessageBoxButtons .OK ,MessageBoxIcon.Asterisk );
FileInfo f2 = new FileInfo(file); StreamWriter write = f2.AppendText();
write.Close(); }
private void btn_tuichu_Click(object sender, EventArgs e) {
DialogResult = MessageBox.Show("确定要退出登录系统吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult == DialogResult.Yes) } } }
this.Close();