如何从文本文件中验证用户名和密码?|Winforms C# [英] How to validate username and password from text file? | Winforms C#

查看:32
本文介绍了如何从文本文件中验证用户名和密码?|Winforms C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我制作了 textbox1(for username)、textbox2(for password) 和 button1(check).之后:

First I made textbox1(for username) , textbox2(for password) and button1(check). After:

private void button1_Click(object sender, EventArgs e)
{
    FileStream fs = new FileStream(@"D:\C#\test.txt", FileMode.Open, FileAccess.Read, FileShare.None);
    StreamReader sr = new StreamReader(fs);
}

我想从 test.txt 的第一行检查用户名(等于在 textbox1 中从我添加的文本)和第二行的密码.

I want to check username from the first line of test.txt (equals like added from me text in textbox1) and password from the second line.

抱歉我的英语不好.

推荐答案

你可以试试这样的:

private void button1_Click(object sender, EventArgs e){
     string[] lines = System.IO.File.ReadAllLines(@"D:\C#\test.txt");
     String username = lines[0];
     String password = lines[1];
}

但是,这不是存储用户名和密码的好方法.我假设你只是在测试一些东西.

However, it's not a very good way to store your usernames and passwords. I'm assuming you're just testing something out.

这篇关于如何从文本文件中验证用户名和密码?|Winforms C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆