Esempio n. 1
0
        private void Loginbtn_Click(object sender, RoutedEventArgs e)
        {
            bool Userkey = dictionary.ContainsKey(Username_Textbox.Text);
            bool Passkey = dictionary.ContainsValue(Password_Tb.Password);

            if (Userkey && Passkey)
            {
                MainWindow mw = new MainWindow();
                mw.Background = Brushes.LightBlue;
                mw.Title      = "Welcome";
                mw.ShowDialog();
            }
            else
            {
                MessageBox.Show("Your Username or Password is Incoreect", "Login Failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            Username_Textbox.Clear();
            Password_Tb.Clear();
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string UserName  = UserName_Tb.Text;
            string Password  = Password_Tb.Text;
            bool   userFound = false;

            string[] lines  = System.IO.File.ReadAllLines("login.txt");
            string[] splits = new string[] { };
            File.Create("Users.txt").Close();
            foreach (string set in lines)
            {
                splits = set.Split(',');
                string UserName1 = splits[0];
                string Password1 = splits[1];
                string UserType  = splits[2];
                File.AppendAllText("Users.txt", UserName1 + "|" + Password1 + "|" + UserType + Environment.NewLine);
                if (UserName == UserName1 && Password == Password1)
                {
                    this.Hide();
                    TextEditor t1 = new TextEditor();
                    userFound = true;
                    UserName_Tb.Clear();
                    Password_Tb.Clear();
                    t1.UserName = UserName1;
                    t1.UserType = UserType;
                    t1.ShowDialog();
                    break;
                }
            }
            if (userFound == false)
            {
                UserName_Tb.Clear();
                Password_Tb.Clear();
                MessageBox.Show("Incorrect Credentials", "User Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }