Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

       }
Posted
Updated 4-Feb-18 20:55pm
Comments
an0ther1 4-Feb-18 23:52pm    
Well apart from the obvious - you shouldn't be storing a username & password in a text file - the basic process should go as follows;
a) Capture username & password & click event
b) Increment counter
c) Pass these values to your authentication method
d) Validate the provided details
e) Store user details - if required
f) Return a value to indicate success or fail
g) If fail, check to see if login attempts have been exhausted - exit if so, if not show appropriate message
Immediate problems;
Your button_click event handler does not call your ValidatePassword method
Your StreamReader in LireClient will read each line in your file & split the content to a single element array with 2 dimensions - hence only the last line will be stored.
I suggest you look at the MSDN website for information on a StreamReader for a start, then look at how you can handle authentication
MSDN StreamReader Class
Login Form using Windows Forms - Beginners

Kind Regards
Arunprasath Natarajan 5-Feb-18 2:18am    
I agree with him - You should store the Username and Password in text file.

1 solution

Never store a password as a plain text!

Please, read this: Password Storage: How to do it.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900