Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Checks if customer has created an account and asks to Sign Up first if he hasn't
            string path = Application.StartupPath + "\\CUSTOMER\\" + un + ".txt";

            if (File.Exists(path) == false)
            {
                SoundPlayer sp = new SoundPlayer(Application.StartupPath + "//SOUNDS//" + "Sound_error.wav");
                sp.Play();
                MessageBox.Show("Username doesn't exist. Please Sign Up first.");
            }
            else
            {
                // If customer has created an account then open the file for the customer using the username entered in the username text box
                string[] arrline = File.ReadAllLines(path); // Reads the whole file and saves each line to a string array

                fname = arrline[0];                         // 1st line of file = First name (will be passed to Customer Portal Form for welcome message)
                uname = arrline[2];                         // 3rd line of file = Username (public static string)

                if (arrline[3] == pw)                       // If password read from 4th line of file matches password entered by user then login successful and Customer Portal opens
                {
                    this.Close();
                    CUSTOMER_PORTAL c = new CUSTOMER_PORTAL(fname);
                    c.Show();
                }
                else // If not, display error message and play error sound
                {
                    SoundPlayer sp = new SoundPlayer(Application.StartupPath + "//SOUNDS//" + "Sound_error.wav");
                    sp.Play();
                    MessageBox.Show("Invalid Password!");
                }
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*   string pass;
             * string path =  Application.StartupPath + "\\CUSTOMER\\" + un + ".txt";
             *
             * StreamReader sw = new StreamReader(path);
             *
             * pass = sw.ReadLine();
             *
             *
             * if (String.Equals(pass, pw))
             * {
             *     MessageBox.Show("Welcome!");
             * }
             * else
             * {
             *     MessageBox.Show("Invalid Username Or Password!");
             * }
             * sw.Close();
             */
            string path = Application.StartupPath + "\\CUSTOMER\\" + un + ".txt";

            using (StreamReader sr = new StreamReader(path))
            {
                fname      = sr.ReadLine();
                lname      = sr.ReadLine();
                uname      = sr.ReadLine();
                passw      = sr.ReadLine();
                mail       = sr.ReadLine();
                cnic       = sr.ReadLine();
                address    = sr.ReadLine();
                creditcard = sr.ReadLine();
                ph_no      = sr.ReadLine();
                dob        = sr.ReadLine();

                sr.Close();
            }


            const int l = 4;

            string line;


            line = func(l);


            if (String.Equals(line, pw))
            {
                var = username.Text;
                MessageBox.Show("Welcome!");
                CUSTOMER_PORTAL c = new CUSTOMER_PORTAL();
                c.Show();
            }
            else
            {
                MessageBox.Show("Invalid Username Or Password!");
            }
        }