如何使用.text文件验证用户名和密码 [英] How do validate username and password with .text file

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

问题描述

我正在尝试从我的驱动器上的.Text文件验证ATM用户名和NIP。我真的不知道怎么做,所以如果你们有任何可以帮助我的提示,那就太棒了



我尝试过的:



***登录页面****



Hi, i'm trying to validate ATM Username and NIP from a .Text file on my drive. I really don't know how to do it so if any of you got any tips that could help me, that would be great

What I have tried:

***Logon page****

public partial class MainWindow : Window
    {
        public static GestionnaireGuichet guichet = new GestionnaireGuichet();

        public MainWindow()
        {
            InitializeComponent();
        }

        int count = 0;
        private void button_Click(object sender, RoutedEventArgs e)
        {
            
            if (count == 3)
            {
                this.Close();
            }
            if ((string.IsNullOrEmpty(user.Text)) || (string.IsNullOrEmpty(pass.Password)))
            {
                MessageBox.Show("Provide a valide username and password");
            }
            if ((user.Text.Length > 0) || (pass.Password.Length > 0))
            

            { 
                OperationCompte operation = new OperationCompte();
                this.Close();
                operation.Show();

            }
            else
                count++;
        
        }





***使用此验证***





***Using this for validation***

public bool ValidatePassword(string username, string password)
        {
            string[] strArray = System.IO.File.ReadAllLines(@"D:\Project\Guichet\Guichet\bin\Debug\client.txt");

            if (username != strArray[0]) return false; //Wrong username

            if (password != strArray[1]) return false; //Wrong password

            if (username == strArray[0] && password == strArray[1]) return true; //good validation




            else
                return false;

        }





***我用这个来阅读文本文件***





***I'm using this to read text file***

public bool LireClient()
       {
           string[] strArray;
           StreamReader sr = new StreamReader("client.txt");
           string strLine = sr.ReadLine();
           while (strLine != null)
           {
               strArray = strLine.Split(',');
               client.Add(new Client(strArray[0], strArray[1]));
               strLine = sr.ReadLine();
           }
           sr.Close();
           return true;

       }

推荐答案

从不存储密码作为纯文本!



请阅读:密码存储:怎么做。 [ ^ ]


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

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