예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            linqtoregdbDataContext db = new linqtoregdbDataContext();

            var getUser = from usr in db.users
                          where usr.username == User.username
                          select usr;
            var currentUser = getUser.First(x => true);

            if (textBox2.Text != textBox3.Text)
            {
                MessageBox.Show("Passwords do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (currentUser.password == Hasher.GetHash(textBox1.Text).ToString() || admin)
            {
                currentUser.password = Hasher.GetHash(textBox2.Text).ToString();
                db.SubmitChanges();
                MessageBox.Show("Password changed successfully");
                this.Close();
            }
            else
            {
                MessageBox.Show("Current password incorrect.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //label1.Text = "";
            //label2.Text = "";
            //label3.Text = "";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool user = false;

            //string line;
            //System.IO.StreamReader database = new System.IO.StreamReader("users.in");
            //while (!database.EndOfStream)
            {
                user = true;
                user currentUser = new user();
                //line=database.ReadLine();
                //string username = "";
                //int i = 0;
                //for(i=0;line[i]!=' ';i++)
                //{
                linqtoregdbDataContext db = new linqtoregdbDataContext();
                bool valid = false;

                var queryIsUsername = from usr in db.users
                                      select usr;

                List <string> allUsernames = new List <string>();
                foreach (var c in queryIsUsername)
                {
                    allUsernames.Add(c.username.ToLower());
                    if (c.username.ToLower() == maskedTextBox1.Text.ToLower())
                    {
                        User.username = c.username;
                        valid         = true;
                        currentUser   = c;
                    }
                }
                if (currentUser.password != Hasher.GetHash(maskedTextBox2.Text).ToString())
                {
                    MessageBox.Show("Invalid username/password combination!");
                }
                else
                {
                    //username += line[i];
                    //if (maskedTextBox1.Text.ToString().ToLower()[i] != char.ToLower(line[i]))
                    //{
                    //    user = false;
                    //    break;
                    //}
                    //}
                    //if (user)
                    //{
                    //    User.username = username;
                    //    i = 11;
                    //    user = false;
                    //    foreach (char c in maskedTextBox2.Text.ToString())
                    //    {
                    //        user = true;
                    //        if (c != line[i])
                    //        {
                    //            user = false;
                    //            break;
                    //        }
                    //        i++;
                    //    }
                    //    if (user)
                    //{
                    //i = 70;
                    //string status="";
                    //for(i=70;i<line.Length&&line[i]!='\n'&&line[i]!=' ';i++)
                    //    status+=line[i];
                    string name = "Welcome,\n";
                    name += currentUser.lastName + ", " + currentUser.firstName;
                    //for (i = 22; line[i] != ' '; i++)
                    //    name += line[i];
                    MessageBox.Show(name);
                    User.type = currentUser.usertype;
                    //if (User.type == "admin")
                    //{
                    //    AdminWindow adminScreen = new AdminWindow(this, User);
                    //    adminScreen.Show();
                    //}
                    //else if (User.type == "faculty")
                    //{
                    //    FacultyHome facultyScreen = new FacultyHome(User, this);
                    //    facultyScreen.Show();
                    //}
                    //else
                    //{
                    Home screen = new Home(this, User);
                    screen.Show();
                    //}
                    this.Hide();
                }
            }
            //if (maskedTextBox2.Text.ToString() == "pong")
            //{
            //    linqtoregdbDataContext db = new linqtoregdbDataContext();
            //    var queryUsername = from usr in db.users
            //                        where usr.username.ToLower()==maskedTextBox1.Text.ToLower()
            //                        select usr.username;
            //    if (queryUsername.Count() == 1)
            //    {
            //        PongForm pongWindow = new PongForm(this,queryUsername.First());
            //        pongWindow.Show();
            //        this.Hide();
            //    }
            //    /*MessageBox.Show("Welcome");
            //    Classes screen = new Classes(this);
            //    screen.Show();
            //    this.Hide();*/
            //}
            //database.Close();
            maskedTextBox2.Text = "";
            //maskedTextBox1.Text="";
        }
예제 #3
0
        private void AddUsers()
        {
            System.IO.StreamReader inFile = new System.IO.StreamReader(textBox1.Text);
            int    lineNum     = 0;
            int    numInserted = 0;
            string inLine;
            Regex  reg       = new Regex(@"[a-zA-Z ]{10}\ [a-zA-Z ]{10}\ [a-zA-Z ]{15}\ [a-zA-Z ]{15}\ [a-zA-Z ]{15}\ [a-zA-Z ]{10}");
            bool   keepGoing = true;

            while (!inFile.EndOfStream && keepGoing)
            {
                inLine = inFile.ReadLine();
                lineNum++;
                if (!reg.IsMatch(inLine))
                {
                    DialogResult result = MessageBox.Show("Error - inproper input format on line " + lineNum.ToString() + ". Continue?", "Error", MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        keepGoing = false;
                    }
                }
                else
                {
                    linqtoregdbDataContext db = new linqtoregdbDataContext();
                    string usernameIn, firstNameIn, lastNameIn, passwordIn, statusIn;
                    usernameIn  = TrimSpaces(inLine.Substring(0, 10));
                    passwordIn  = Hasher.GetHash(TrimSpaces(inLine.Substring(11, 10))).ToString();
                    firstNameIn = TrimSpaces(inLine.Substring(22, 15));
                    lastNameIn  = TrimSpaces(inLine.Substring(54, 15));
                    statusIn    = TrimSpaces(inLine.Substring(70, 10));

                    var queryGetAdvisor = (from usr in db.users
                                           where usr.username == statusIn
                                           select usr.userID).FirstOrDefault();
                    user newUser = new user
                    {
                        username  = usernameIn,
                        password  = passwordIn,
                        firstName = firstNameIn,
                        lastName  = lastNameIn,
                        advisor   = (queryGetAdvisor == default(int)) ? null : (int?)queryGetAdvisor,
                        usertype  = (queryGetAdvisor == default(int)) ? "student" : statusIn
                    };
                    try
                    {
                        db.users.InsertOnSubmit(newUser);
                        db.SubmitChanges();
                        numInserted++;
                    }
                    catch (Exception)
                    {
                        DialogResult result = MessageBox.Show("Error - invalid user insertion attempted. Skip user and continue?", "Error", MessageBoxButtons.YesNo);
                        if (result == System.Windows.Forms.DialogResult.No)
                        {
                            keepGoing = false;
                        }
                    }
                }
            }
            MessageBox.Show(numInserted.ToString() + " users inserted successfully.");
            inFile.Close();
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool keepGoing            = true;
            user usr                  = new user();
            linqtoregdbDataContext db = new linqtoregdbDataContext();

            string[] types = { "student", "faculty", "admin", "manager" };

            var queryGetUserID = from quser in db.users
                                 where quser.username == comboBox2.SelectedItem.ToString()
                                 select quser;

            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a User Type.");
                keepGoing = false;
            }
            else
            {
                if ((string)comboBox1.SelectedItem == "Student")
                {
                    if (comboBox2.SelectedIndex == -1)
                    {
                        MessageBox.Show("Please select an advisor.");
                        keepGoing = false;
                    }
                    else
                    {
                        var advisorID = queryGetUserID.FirstOrDefault().userID;
                        usr = new user
                        {
                            username  = textBox1.Text,
                            password  = Hasher.GetHash(textBox2.Text).ToString(),
                            firstName = textBox3.Text,
                            lastName  = textBox5.Text,
                            usertype  = types[comboBox1.SelectedIndex],
                            advisor   = advisorID
                        };
                    }
                }
                else
                {
                    usr = new user
                    {
                        username  = textBox1.Text,
                        password  = Hasher.GetHash(textBox2.Text).ToString(),
                        firstName = textBox3.Text,
                        lastName  = textBox5.Text,
                        usertype  = types[comboBox1.SelectedIndex]
                    };
                }
                if (usr.username == "")
                {
                    keepGoing = false;
                    MessageBox.Show("Username cannot be blank.");
                }
                else if ((from usrs in db.users
                          where usrs.username == usr.username
                          select usrs).Any())
                {
                    keepGoing = false;
                    MessageBox.Show("Username already exists, please choose a different one.");
                }
                else if (usr.usertype == "manager")
                {
                    DialogResult drslt = MessageBox.Show("Are you certain you wish to create a new manager?", "Confirm User Creation", MessageBoxButtons.YesNo);
                    if (drslt == DialogResult.No)
                    {
                        keepGoing = false;
                    }
                }
                if (keepGoing)
                {
                    db.users.InsertOnSubmit(usr);
                    db.SubmitChanges();
                    MessageBox.Show("User added successfully!");
                    this.Close();
                }
            }
        }