예제 #1
0
        //sign in button
        private void ButtonSignIn_Click(object sender, RoutedEventArgs e)
        {
            //loads the array of usernames
            //then checks if given username is in array
            //if it is in array then checks the sha256 of password within index in array of passwords
            //if returned index is -1 then username doesn't exist
            isRemembered = Convert.ToBoolean(CheckboxRememberMeSignin.IsChecked);
            tempUsername = TextboxUsernameSignin.Text;
            temp_id      = Array.IndexOf(student_usernames, tempUsername);
            int temp_id_teacher = Array.IndexOf(teacher_usernames, tempUsername);

            //check if given username is student
            if (temp_id > -1 && temp_id_teacher == -1)
            {
                isTeacher = false;
                isStudent = true;
            }
            //check if given username is teacher
            else if (temp_id == -1 && temp_id_teacher > -1)
            {
                isTeacher = true;
                isStudent = false;
            }
            //if given username is none them
            else if (temp_id == -1 && temp_id_teacher == -1)
            {
                hasError = true;
                TextStatusSignIn.Text = signin_error;
            }

            //then checks the given password with returned index of username
            //first if previous logic returned isTeacher = true
            //and hasError = false
            if (isTeacher == true && isStudent == false && hasError == false)
            {
                temp_pass = Methods.EncryptPass(TextboxPasswordSignin.Text);
                if (temp_pass == teacher_passwords[temp_id_teacher])
                {
                    hasError     = false;
                    account_type = "teacher";
                }
                else
                {
                    hasError = true;
                    TextStatusSignIn.Text = signin_error;
                }
            }

            //the same logic but for student now
            if (isStudent == true && isTeacher == false && hasError == false)
            {
                temp_pass = Methods.EncryptPass(TextboxPasswordSignin.Text);
                if (temp_pass == student_passwords[temp_id])
                {
                    hasError     = false;
                    account_type = "student";
                }
                else
                {
                    hasError = true;
                    TextStatusSignIn.Text = signin_error;
                }
            }

            //check if username and password should be saved
            if (isRemembered == true && hasError == false)
            {
                m.FileWrite(last_session_path, TextboxUsernameSignin.Text);
                m.FileWrite(remembered_path, Convert.ToString(isRemembered));

                //saving account type
                if (isTeacher == true && isStudent == false)
                {
                    m.FileWrite(login_is_teacher, "teacher");

                    //redirect to teachers page
                    TeacherSubjects teacherSubjects = new TeacherSubjects();
                    teacherSubjects.Show();
                    Close();
                }
                else if (isTeacher == false && isStudent == true)
                {
                    m.FileWrite(login_is_teacher, "student");

                    //redirect to students page
                    SubjectsStudent subjectsStudent = new SubjectsStudent();
                    subjectsStudent.Show();
                    Close();
                }
            }

            //logic for if credentials is not going to be saved
            if (isRemembered == false && hasError == false)
            {
                m.FileWrite(last_session_path, TextboxUsernameSignin.Text);

                if (isTeacher == true && isStudent == false)
                {
                    m.FileWrite(login_is_teacher, "teacher");
                }
                else if (isTeacher == false && isStudent == true)
                {
                    m.FileWrite(login_is_teacher, "student");
                }
            }

            if (account_type == "student" & hasError == false)
            {
                SubjectsStudent subjectsStudent = new SubjectsStudent();
                subjectsStudent.Show();
                Close();
            }
        }
예제 #2
0
        //logic when complete button is clicked
        private void ButtonCompleteSignUpStudent_Click(object sender, RoutedEventArgs e)
        {
            //getting user input
            tempusername  = TextboxUsernameStudentSignUp.Text;
            temppassword  = TextboxPasswordStudentSignUp.Text;
            temppassword1 = TextboxPassword2StudentSignUp.Text;
            tempemail     = TextboxEmailStudentSignUp.Text;
            tempfirstname = TextboxFirstNameStudentSignUp.Text;
            templastname  = TextboxLastNameStudentSignUp.Text;

            int user_id_s = Array.IndexOf(student_usernames, tempusername);
            int user_id_t = Array.IndexOf(teacher_usernames, tempusername);
            int email_s   = Array.IndexOf(student_emails, tempemail);
            int email_t   = Array.IndexOf(teacher_emails, tempemail);

            //checking if credential are ok and free
            if (user_id_s > -1 | user_id_t > -1)
            {
                noError         = false;
                status          = "Username is already taken";
                TextStatus.Text = status;
            }
            if (email_t > -1 | email_s > -1)
            {
                noError         = false;
                status          = "Email address is already used";
                TextStatus.Text = status;
            }
            if (temppassword != temppassword1)
            {
                noError         = false;
                status          = "Passwords doesn't match";
                TextStatus.Text = status;
            }
            if (m.IsValidEmail(tempemail) == false)
            {
                noError         = false;
                status          = "Enter valid email address";
                TextStatus.Text = status;
            }
            if (temppassword.Length < 8)
            {
                noError         = false;
                status          = "Password should be longer or equal to 8 symbol";
                TextStatus.Text = status;
            }
            if (user_id_t == -1 & user_id_s == -1 & email_s == -1 & email_t == -1 & temppassword == temppassword1 & m.IsValidEmail(tempemail) & temppassword.Length >= 8)
            {
                noError = true;

                Directory.CreateDirectory(student_path + student_id);

                m.FileWrite(student_path + student_id + @"\username", tempusername);
                m.FileWrite(student_path + student_id + @"\password", Methods.EncryptPass(temppassword));
                m.FileWrite(student_path + student_id + @"\email", tempemail);
                m.FileWrite(student_path + student_id + @"\firstname", tempfirstname);
                m.FileWrite(student_path + student_id + @"\lastname", templastname);

                student_id++;
                m.FileWrite(student_id_path, Convert.ToString(student_id));
            }

            //if everything ok then redirect to student window
            if (noError == true)
            {
                SubjectsStudent subjectsStudent = new SubjectsStudent();
                subjectsStudent.Show();
                this.Close();
            }
        }