Esempio n. 1
0
        private void ButtonAcceptDialogHost_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxUserName.Text == "")
            {
                var message = "Name required to login!";
                SnackBarDialogHostMessageDisplay(message, 1000);
            }

            if (PasswordBoxUserPassword.Password != "")
            {
                if (PasswordBoxUserPassword.Password.Length < 13)
                {
                    var message = "Password is too short!";
                    SnackBarDialogHostMessageDisplay(message, 1000);
                    PasswordBoxUserPassword.Focus();
                    e.Handled = true;
                }
                else
                {
                    //if userLogin fails
                    if (!SQL_Connect())
                    {
                        var message = "User does not exist!";
                        SnackBarDialogHostMessageDisplay(message, 1000);
                        PasswordBoxUserPassword.Password = "";
                        TextBoxUserName.Text             = "";
                        TextBoxUserName.Focus();
                        return;
                    }



                    Console.WriteLine("Closing Dialog Host");
                    AcceptButtonIsPressed = true;

                    var message1 = "Welcome," + AppUser.Name + "!";
                    SnackbarMessageDisplay(message1, 1000);
                    BUTTONCLOSEDIALOG.Command.Execute(null);
                    var target = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;
                    target.MenuToggleButton.IsEnabled = true;
                    if (!AppUser.isTeacher)
                    {
                        target.ButtonBooks.Visibility = Visibility.Collapsed;
                        target.ButtonUsers.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        target.ButtonBooks.Visibility = Visibility.Visible;
                        target.ButtonUsers.Visibility = Visibility.Visible;
                    }
                    e.Handled = true;
                }
            }
            else
            {
                var message = "CNP can not be empty!";
                SnackBarDialogHostMessageDisplay(message, 1000);
                e.Handled = true;
            }
        }
Esempio n. 2
0
 private bool CheckedUser()
 {
     if (TextBoxUserName.Text.Trim().Equals(string.Empty))
     {
         TextBoxUserName.Focus();
         MessageBox.Show(this, "用户名不能为空!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning);
         return(false);
     }
     else if (TextBoxUserPassword.Password.Trim().Equals(string.Empty))
     {
         TextBoxUserPassword.Focus();
         MessageBox.Show(this, "密码不能为空!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning);
         return(false);
     }
     else if (TextBoxUserName.Text.Trim().Equals("260905") && TextBoxUserPassword.Password.Trim().Equals("260905"))
     {
         //分光度测试界面
         FgdTest window = new FgdTest()
         {
             ShowInTaskbar = false,
             Owner         = this
         };
         window.Show();
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
 public void OnEditing(EditMessage message)
 {
     if (message.ViewModel == DataContext)
     {
         TextBoxUserName.Focus();
         Keyboard.Focus(TextBoxUserName);
     }
 }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserData"] != null)
            {
                Response.Redirect("Default.aspx");
            }

            TextBoxUserName.Focus();
        }
Esempio n. 5
0
        /// <summary>
        /// Displays requested screen section based on received request.
        /// </summary>
        private void ManageScreenVisualization()
        {
            // Initially hide everything on all screens
            LoginSection.Visibility          = Visibility.Collapsed;
            AccessDeniedSection.Visibility   = Visibility.Collapsed;
            ChangePasswordSection.Visibility = Visibility.Collapsed;

            TextBlockApplicationLogin.Visibility = Visibility.Collapsed;
            TextBlockAccessDenied.Visibility     = Visibility.Collapsed;
            TextBlockChangePassword.Visibility   = Visibility.Collapsed;

            // Reset all default buttons
            ButtonLogin.IsDefault  = false;
            ButtonOK.IsDefault     = false;
            ButtonChange.IsDefault = false;

            if (m_displayType == DisplayType.Login)
            {
                TextBoxPassword.Password             = "";
                ButtonLogin.IsDefault                = true;
                TextBlockApplicationLogin.Visibility = Visibility.Visible;
                LoginSection.Visibility              = Visibility.Visible;

                if (string.IsNullOrWhiteSpace(TextBoxUserName.Text))
                {
                    TextBoxUserName.Focus();
                }
                else
                {
                    TextBoxPassword.Focus();
                }
            }
            else if (m_displayType == DisplayType.AccessDenied)
            {
                ButtonOK.IsDefault = true;
                TextBlockAccessDenied.Visibility = Visibility.Visible;
                AccessDeniedSection.Visibility   = Visibility.Visible;
            }
            else if (m_displayType == DisplayType.ChangePassword)
            {
                TextBoxOldPassword.Password        = "";
                TextBoxNewPassword.Password        = "";
                TextBoxConfirmPassword.Password    = "";
                ButtonChange.IsDefault             = true;
                TextBlockChangePassword.Visibility = Visibility.Visible;
                ChangePasswordSection.Visibility   = Visibility.Visible;

                if (string.IsNullOrWhiteSpace(TextBoxChangePasswordUserName.Text))
                {
                    TextBoxChangePasswordUserName.Focus();
                }
                else
                {
                    TextBoxOldPassword.Focus();
                }
            }
        }
Esempio n. 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBoxUserName.Focus();

        if (Session["CurrentUser"] != null)
        {
            Response.Redirect("~/GameServer/ServerOverviewAndMonitor.aspx");
        }

        LabelLoginError.Visible = false;
    }
Esempio n. 7
0
 private void WindowLogin_OnLoaded(object sender, RoutedEventArgs e)
 {
     try
     {
         TextBoxUserName.Focus();
     }
     catch (Exception ex)
     {
         Logger.LogIndustrialMonitoring(ex);
     }
 }
Esempio n. 8
0
 public LoginWindow()
 {
     InitializeComponent();
     if (0 == Global.userAccounts.Count)
     {
         UserAccount admin = new UserAccount()
         {
             UserName     = "******",
             UserPassword = "******",
             Create       = true
         };
         Global.userAccounts.Add(admin);
         Global.SerializeToFile(Global.userAccounts, Global.userAccountsFile);
     }
     TextBoxUserName.Focus();
 }
Esempio n. 9
0
 //账号输入框回车事件,输入完账号后按Enter键即可自动跳转到密码输入框
 private void TextBoxUserName_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
 {
     TextBoxUserPassword.Password = string.Empty;
     if (e.Key == System.Windows.Input.Key.Enter)
     {
         if (TextBoxUserName.Text.Trim().Equals(string.Empty))
         {
             TextBoxUserName.Clear();
             TextBoxUserName.Focus();
             MessageBox.Show(this, "用户名不能为空!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
         else
         {
             TextBoxUserPassword.Focus();
         }
     }
 }
Esempio n. 10
0
 private bool Validate()
 {
     if (string.IsNullOrWhiteSpace(TextBoxUserName.Text))
     {
         MessageBox.Show("Username is mandatory for new users");
         TextBoxUserName.Focus();
         return(false);
     }
     if (string.IsNullOrWhiteSpace(TextBoxPassword.Text))
     {
         MessageBox.Show("Password is mandatory for new users");
         TextBoxPassword.Focus();
         return(false);
     }
     if (ComboBoxAdmin.SelectedIndex < 0)
     {
         MessageBox.Show("Admin status is mandatory for new users");
         ComboBoxAdmin.Focus();
         return(false);
     }
     return(true);
 }
Esempio n. 11
0
        /// <summary>
        /// Logins the user.
        /// </summary>
        /// <param name="sender">Source of this event.</param>
        /// <param name="e">Arguments of this event.</param>
        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            UserInfo userInfo;
            WindowsImpersonationContext impersonationContext = null;
            ISecurityProvider           securityProvider;

            try
            {
                // Determine whether we need to try impersonating the user
                userInfo = new UserInfo(TextBoxUserName.Text);

                // If the application is unable to access the domain, possibly because the local user
                // running the application does not have access to domain objects, it's possible that
                // the user logging in does have access to the domain. So we attempt to impersonate the
                // user logging in to allow authentication to proceed
                if (!userInfo.DomainRespondsForUser && TryImpersonate(userInfo.LoginID, TextBoxPassword.Password, out impersonationContext))
                {
                    try
                    {
                        // Working around a known issue - DirectorySearcher will often throw
                        // an exception the first time it is used after impersonating another
                        // user so we get that out of the way here
                        userInfo.Initialize();
                    }
                    catch (InitializationException)
                    {
                        // Exception is expected so we ignore it
                    }
                }

                // Initialize the security provider
                securityProvider = SecurityProviderCache.CreateProvider(TextBoxUserName.Text);
                securityProvider.SecurePassword = TextBoxPassword.SecurePassword;

                // Attempt to authenticate user
                if (securityProvider.Authenticate())
                {
                    // Setup security principal for subsequent uses
                    SecurityIdentity securityIdentity = new SecurityIdentity(securityProvider);
                    SecurityPrincipal = new SecurityPrincipal(securityIdentity);
                    ClearErrorMessage();
                    ExitSuccess = true;
                }
                else
                {
                    // Verify their password hasn't expired
                    if (securityProvider.UserData.IsDefined && securityProvider.UserData.PasswordChangeDateTime <= DateTime.UtcNow)
                    {
                        // Display password expired message
                        DisplayErrorMessage(string.Format("Your password has expired. {0} You must change your password to continue.", securityProvider.AuthenticationFailureReason));
                        m_displayType = DisplayType.ChangePassword;
                        ManageScreenVisualization();
                        TextBoxPassword.Password = "";
                    }
                    else
                    {
                        // Display login failure message
                        DisplayErrorMessage("The username or password is invalid. " + securityProvider.AuthenticationFailureReason);

                        if (string.IsNullOrWhiteSpace(TextBoxUserName.Text))
                        {
                            TextBoxUserName.Focus();
                        }
                        else
                        {
                            TextBoxPassword.Focus();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayErrorMessage("Login failed: " + ex.Message);

                if (string.IsNullOrWhiteSpace(TextBoxUserName.Text))
                {
                    TextBoxUserName.Focus();
                }
                else
                {
                    TextBoxPassword.Focus();
                }
            }
            finally
            {
                if ((object)impersonationContext != null)
                {
                    impersonationContext.Undo();
                    impersonationContext.Dispose();
                }
            }
        }
Esempio n. 12
0
 void LogonPage_Loaded(object sender, RoutedEventArgs e)
 {
     TextBoxUserName.Focus(Windows.UI.Xaml.FocusState.Programmatic);
 }
Esempio n. 13
0
 /// <summary>
 /// 清空账号和密码信息
 /// </summary>
 private void ClearAccount()
 {
     TextBoxUserName.Text         = string.Empty;
     TextBoxUserPassword.Password = string.Empty;
     TextBoxUserName.Focus();
 }
Esempio n. 14
0
        private void Btn_Add_User_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((TextBoxUserName.Text == "") || (TextBoxUserEmail.Text == "") || (Combo_User_Role.Text == ""))
                {
                    if (TextBoxUserName.Text == "")
                    {
                        MessageBox.Show("Name is required", "Warning", MessageBoxButton.OK);
                        TextBoxUserName.Focus();
                    }
                    else if (TextBoxUserEmail.Text == "")
                    {
                        MessageBox.Show("Email is required", "Warning", MessageBoxButton.OK);
                        TextBoxUserEmail.Focus();
                    }
                    else if (Combo_User_Role.Text == "")
                    {
                        MessageBox.Show("Role is required", "Warning", MessageBoxButton.OK);
                        Combo_User_Role.Focus();
                    }
                }
                else
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are You Sure?", "Insert Confirmation", System.Windows.MessageBoxButton.YesNo);

                    if (messageBoxResult == MessageBoxResult.Yes)


                    {
                        string Password       = Guid.NewGuid().ToString();
                        var    checkuseremail = connection.Users.FirstOrDefault(S => S.Email == TextBoxUserEmail.Text);
                        var    userrole       = connection.Roles.FirstOrDefault(Y => Y.Id == cb_role);
                        if (checkuseremail == null)
                        {
                            var input_user = new User(TextBoxUserName.Text, TextBoxUserEmail.Text, Password, userrole);
                            connection.Users.Add(input_user);
                            var insert = connection.SaveChanges();

                            if (insert >= 1)
                            {
                                MessageBox.Show("User has been inserted");
                            }
                            TB_M_User.ItemsSource = connection.Users.ToList();

                            Outlook._Application openapp  = new Outlook.Application();
                            Outlook.MailItem     sentmail = (Outlook.MailItem)openapp.CreateItem(Outlook.OlItemType.olMailItem);
                            sentmail.To         = TextBoxUserEmail.Text;
                            sentmail.Subject    = "Your Password " + DateTime.Now.ToString("dd/MM/yyyy");
                            sentmail.Body       = "Dear " + TextBoxUserName.Text + "\nThis Is Your Password : "******"Your email has been sent!", "Message", MessageBoxButton.OK);
                            reset_adduser();
                        }
                        else
                        {
                            MessageBox.Show("Email has been used");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Connect to the SQL_database for user login
        /// </summary>
        private bool SQL_Connect()
        {
            try
            {
                Console.WriteLine("Connecting to SQL SERVER");
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource     = "tcp:libraryoop.database.windows.net,1433";
                builder.UserID         = "Library";
                builder.Password       = "******";
                builder.InitialCatalog = "Library";

                Console.WriteLine("Conecting to SQL server.....");
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();
                    Console.WriteLine("Connection Succesfull");

                    Console.WriteLine("Attempting LogIN");
                    StringBuilder sb = new StringBuilder();
                    sb.Append("SELECT * from " + ComboBoxRank.SelectionBoxItem.ToString() + "s where Prenume = @nume AND CNP=@cnp;");
                    String sql = sb.ToString();



                    //check if user exists
                    using (SqlCommand sql_command = new SqlCommand(sql, connection))
                    {
                        sql_command.Parameters.AddWithValue("@nume", TextBoxUserName.Text.ToString());
                        sql_command.Parameters.AddWithValue("@cnp", PasswordBoxUserPassword.Password.ToString());

                        using (SqlDataReader reader = sql_command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                AppUser.SetName(reader["Prenume"] as string);
                                AppUser.SetLastName(reader["Nume"] as string);
                                AppUser.SetTeacher((ComboBoxRank.SelectionBoxItem.ToString() != "Librarian") ? false : true);
                                AppUser.SetCNP(PasswordBoxUserPassword.Password.ToString());

                                if (AppUser.AnAbs > DateTime.Now.Year && !AppUser.isTeacher)
                                {
                                    var message = "User is no more a Student";
                                    SnackBarDialogHostMessageDisplay(message, 1000);
                                    PasswordBoxUserPassword.Password = "";
                                    TextBoxUserName.Text             = "";
                                    TextBoxUserName.Focus();
                                    return(false);
                                }


                                if (!AppUser.isTeacher)
                                {
                                    AppUser.SetAnAbs(reader.GetInt32(reader.GetOrdinal("An_absolvire")));
                                }
                                AppUser.AddBooks(reader["BookList"] as string);
                            }
                            else
                            {
                                Console.WriteLine("LogIn failed! User does not exist! \nReseting Values...."); return(false);
                            }
                        }
                    }
                    Console.WriteLine("User found");
                    //if user exists LOGIN
                    sb.Clear();
                    sb.Append("SELECT Profilepic from " + ComboBoxRank.SelectionBoxItem.ToString() + "s where Prenume = @nume AND CNP=@cnp;");
                    sql = sb.ToString();
                    //retrieve profilePicture
                    using (SqlCommand sql_command = new SqlCommand(sql, connection))
                    {
                        sql_command.Parameters.AddWithValue("@nume", TextBoxUserName.Text.ToString());
                        sql_command.Parameters.AddWithValue("@cnp", PasswordBoxUserPassword.Password.ToString());
                        using (SqlDataReader reader = sql_command.ExecuteReader())
                        {       //nu merge tui ceapa lui
                            if (reader.Read())
                            {
                                if (reader["Profilepic"] != null)
                                {
                                    AppUser.SetProfilePic(reader.GetString(reader.GetOrdinal("ProfilePic")));
                                    Console.WriteLine("Changing profile picture");
                                    ProfilePicture.ImageSource  = new BitmapImage(new Uri(reader.GetString(reader.GetOrdinal("Profilepic")), UriKind.Absolute));
                                    NoProfilePicture.Visibility = Visibility.Hidden;
                                }
                            }
                        }
                    }
                    return(true);
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(false);
        }