예제 #1
0
        public void CreateLoginAndCopy()
        {
            var newLoginProperties = new LoginProperties {
                Sid = new byte[]
                { 0xEA, 0x11, 0x6E, 0x4D, 0x2A, 0x9E, 0x43, 0x4B, 0x84, 0x04, 0xB9, 0x93, 0xF4, 0x8F, 0x1E, 0xA5 },
                Name            = LoginName,
                Password        = Password,
                LoginType       = LoginType.SqlLogin,
                DefaultDatabase = DefaultDatabase
            };

            var initialLogin = CreateTestLogin(newLoginProperties);

            TestLoginExists(initialLogin);

            // These login properties will have the password hash
            var loginProperties = initialLogin.Properties();

            initialLogin.Drop();

            var copiedLogin = CreateTestLogin(loginProperties);

            TestLoginExists(copiedLogin);
            Assert.Equal(newLoginProperties.DefaultDatabase, copiedLogin.Properties().DefaultDatabase);

            ConnectViaLogin(LoginName, Password);
        }
예제 #2
0
        /// <summary>
        /// Function to check the User Role of  Logged User.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>List</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-19,2016</createdOn>
        public List <string> GetUserRole(LoginProperties objLoginProp)
        {
            // creating the object of PortStorageEntities Database
            using (PortStorageEntities objAppWorksEntities = new PortStorageEntities())
            {
                List <string> userRolelist = new List <string>();

                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                try
                {
                    int userId = (from T in objAppWorksEntities.Users
                                  where T.UserCode == objLoginProp.Username &&
                                  (T.Password == objLoginProp.Password || T.PIN == objLoginProp.Password)
                                  select T.UserID).FirstOrDefault();

                    if (userId != 0)
                    {
                        userRolelist = (from userRole in objAppWorksEntities.UserRoles
                                        where userRole.UserID == userId
                                        select userRole.RoleName).ToList();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                }

                return(userRolelist);
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns></returns>
        public LoginProperties GetLoggedInUserDetails(LoginProperties loginProps)
        {
            // creating the object of PortStorageEntities Database
            using (PortStorageEntities objAppWorksEntities = new PortStorageEntities())
            {
                var userDetails = (from user in objAppWorksEntities.Users
                                   where user.UserCode == loginProps.Username &&
                                   (user.Password == loginProps.Password || user.PIN == loginProps.Password)
                                   select user).FirstOrDefault();

                if (userDetails != null)
                {
                    //if FirstName OR LastName is empty then show same Username on Main window
                    if (string.IsNullOrEmpty(userDetails.FirstName) || string.IsNullOrEmpty(userDetails.LastName))
                    {
                        loginProps.FullUserName = loginProps.Username;
                    }
                    else
                    {
                        loginProps.FullUserName = string.Format("{0} {1}", userDetails.FirstName, userDetails.LastName);
                    }

                    loginProps.UserRoles = (from userRole in objAppWorksEntities.UserRoles
                                            where userRole.UserID == userDetails.UserID
                                            select userRole.RoleName).ToList();
                }
            }

            return(loginProps);
        }
예제 #4
0
 internal LoginProperties UpdateDefaultDb(LoginProperties loginProperties)
 {
     loginProperties.DefaultDatabase =
         _options.Source.Name.Equals(loginProperties.DefaultDatabase, StringComparison.InvariantCultureIgnoreCase)
   ? _options.Destination.Name
   : "master";
     return(loginProperties);
 }
예제 #5
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            UserInformationProperties _userSession = new UserInformationProperties();
            LoginProperties           logindata    = new LoginProperties();

            if ((textBoxUserName.Text != null) && (textBoxPassword.Text != null))
            {
                logindata.Username = textBoxUserName.Text;
                logindata.Password = textBoxPassword.Text;
                _userSession       = loginHandler.validateUserCredentials(logindata);



                if (_userSession != null)
                {
                    splashscreen.Hide();
                    this.Enabled = false;
                    this.Visible = false;

                    if (_userSession.Role.Equals("MANAGER"))
                    {
                        ManagerMainWindow managerWindow = new ManagerMainWindow(_userSession);
                        managerWindow.Text = _userSession.Name;
                        managerWindow.Show();
                    }
                    else if (_userSession.Role.Equals("VENDOR"))
                    {
                        com.windows.forms.CustomerMainWindow customerWindow = new com.windows.forms.CustomerMainWindow(_userSession);
                        customerWindow.Text = _userSession.Vendor_Name;
                        customerWindow.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Username/Password".ToUpper(), "Login failed".ToUpper(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("PLEASE PROVIDE USERNAME AND PASSWORD PROPERLY".ToUpper(), "Login failed".ToUpper(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #6
0
        /// <summary>
        /// Get all the user details about once login is verified
        /// </summary>
        /// <param name="loginProps"></param>
        /// <returns></returns>
        public LoginProperties GetLoggedInUserDetails(LoginProperties loginProps)
        {
            LoginDAL loginDAL = new LoginDAL();

            CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            try
            {
                loginProps = loginDAL.GetLoggedInUserDetails(loginProps);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }

            return(loginProps);
        }
예제 #7
0
        /// <summary>
        /// Function to Get Logged User Information.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>string</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-20,2016</createdOn>
        public string LoggedUser(LoginProperties objLoginProp)
        {
            // creating the object of PortStorageEntities Database
            using (PortStorageEntities objAppWorksEntities = new PortStorageEntities())
            {
                string fullName = string.Empty;

                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                try
                {
                    var userDetails = (from user in objAppWorksEntities.Users
                                       where user.UserCode == objLoginProp.Username &&
                                       (user.Password == objLoginProp.Password || user.PIN == objLoginProp.Password)
                                       select user).FirstOrDefault();

                    if (userDetails != null)
                    {
                        //if FirstName OR LastName is empty then show same Username on Main window
                        if (string.IsNullOrEmpty(userDetails.FirstName) || string.IsNullOrEmpty(userDetails.LastName))
                        {
                            fullName = objLoginProp.Username;
                        }
                        else
                        {
                            fullName = string.Format("{0} {1}", userDetails.FirstName, userDetails.LastName);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                }

                return(fullName);
            }
        }
        //Validate user login with database
        public UserInformationProperties validateUserLogin(LoginProperties userCreds)
        {
            DataSet reader;
            List <KeyValuePair <string, string> > tableQueryData         = new List <KeyValuePair <string, string> >();
            UserInformationProperties             userProfileInformation = new UserInformationProperties();

            try
            {
                string queryString = "SELECT NAME,CONTACT,ADDRESS,EMAIL_ID,USER_ID,PASSWORD,ROLE,IS_VENDOR,VENDOR_ID,VENDOR_NAME,STATUS FROM USER_TABLE WHERE USER_ID=@USERID AND PASSWORD=@PASSWORD AND STATUS='ACTIVE'";
                tableQueryData.Add(new KeyValuePair <string, string>("@USERID", userCreds.Username));
                tableQueryData.Add(new KeyValuePair <string, string>("@PASSWORD", userCreds.Password));

                reader = DatabaseConnectionHandler.executeSelectQuery(queryString, tableQueryData);
                if (reader != null)
                {
                    userProfileInformation = getSingleUserInfo(userCreds.Username);
                }
            }
            catch (Exception ex) { Console.WriteLine("Login issue occured", ex.Message); }

            return(userProfileInformation);
        }
예제 #9
0
        /// <summary>
        /// Function to Get the RoleName of Logged User.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>List</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-19,2016</createdOn>
        public List <string> GetUserRole(LoginProperties objLoginProp)
        {
            LoginDAL objLoginDAL = new LoginDAL();  /// Creating Object for LoginDAL.

            CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            List <string> objUserRoleList = new List <string>();

            try
            {
                /// Calling GetUserRole Method from LoginDal and Get Logged User User Role.
                objUserRoleList = objLoginDAL.GetUserRole(objLoginProp);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
            return(objUserRoleList);
        }
예제 #10
0
        /// <summary>
        /// Function to Get the Login Credentials.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>Bool</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-13,2016</createdOn>
        public LoginResult ValidateLogin(LoginProperties objLoginProp)
        {
            LoginResult result      = new LoginResult();
            LoginDAL    objLoginDAL = new LoginDAL(); /// Creating Object for LoginDAL Class

            CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            try
            {
                /// Calling Validate Login Mentod from LoginDAL
                result = objLoginDAL.ValidateLogin(objLoginProp);
            }
            catch (Exception ex)
            {
                CommonDAL.logger.LogError(this.GetType(), ex);
                throw ex;
            }
            finally
            {
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
            return(result);
        }
예제 #11
0
        /// <summary>
        /// Function to get the information of Logged User.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>string</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-20,2016</createdOn>
        public string GetUserName(LoginProperties objLoginProp)
        {
            LoginDAL objLoginDAL = new LoginDAL();  /// Creating Object for LoginDAL.

            CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            string userName = string.Empty;

            try
            {
                /// Calling UserName Method for User's Name.
                userName = objLoginDAL.LoggedUser(objLoginProp);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
            return(userName);
        }
예제 #12
0
 public RestoreTests()
 {
     _loginProperties = new LoginProperties {
         DefaultDatabase = "foo"
     };
 }
 public TelnetCommandRoute(
     LoginProperties InLoginProperties)
 {
     mLoginProperties      = InLoginProperties;
     CommandPromptPatterns = new string[] { ">" };
 }
예제 #14
0
 public UserInformationProperties validateUserCredentials(LoginProperties loginInfo)
 {
     return(userSessionHandler.validateUserLogin(loginInfo));
 }
예제 #15
0
 public void AddRole(LoginProperties login, RoleProperties role)
 {
     _listener.ForEachAgInstance(server => server.AddRole(login, role));
 }
예제 #16
0
 public void DropLogin(LoginProperties login)
 {
     _listener.ForEachAgInstance(server => server.DropLogin(login));
 }
예제 #17
0
 private FacadeLogin CreateTestLogin(LoginProperties loginProperties)
 {
     return(new FacadeLogin(loginProperties, Server));
 }
예제 #18
0
        /// <summary>
        /// Function to check the Login Credentials.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>Bool</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-13,2016</createdOn>
        public LoginResult ValidateLogin(LoginProperties objLoginProp)
        {
            // creating the object of PortStorageEntities Database
            using (PortStorageEntities objAppWorksEntities = new PortStorageEntities())
            {
                LoginResult result = new LoginResult();
                CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                try
                {
                    SqlParameter objSqlParam = new SqlParameter();
                    var          procResult  = new SqlParameter
                    {
                        ParameterName = "@procResult",
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Output,
                        Size          = 50
                    };
                    var paramUserCode = new SqlParameter
                    {
                        ParameterName = "@UserCode",
                        Value         = objLoginProp.Username,
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Input
                    };
                    var paramPassword = new SqlParameter
                    {
                        ParameterName = "@Password",
                        Value         = objLoginProp.Password,
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Input
                    };
                    var paramHostName = new SqlParameter
                    {
                        ParameterName = "@HostName",
                        Value         = Dns.GetHostName(),
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Input
                    };
                    var paramBuildDate = new SqlParameter
                    {
                        ParameterName = "@BuildDate",
                        Value         = DateTime.Now,
                        SqlDbType     = SqlDbType.DateTime,
                        Direction     = ParameterDirection.Input
                    };
                    /// Calling The Stored Procedure
                    objAppWorksEntities.Database.ExecuteSqlCommand("exec @procResult = spDATSLogin @UserCode, @Password,@HostName,@BuildDate", paramUserCode, paramPassword, paramHostName, paramBuildDate, procResult);
                    var resultValue = procResult.Value;
                    if (resultValue != null)
                    {
                        if (Convert.ToInt32(resultValue) == 0)
                        {
                            result.IsLoginSuccessful = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    CommonDAL.logger.LogError(this.GetType(), ex);
                    throw;
                }
                finally
                {
                    CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                }

                return(result);
            }
        }
예제 #19
0
        private void OnJniorConnectionNotify(Jnior jnior, StatusArgs args)
        {
            updateIcon();
            updateMonitorStatus();

            // Don't spam
            if (args.Status == jnior_dll_calls.STATUS_CONNECTING || args.Status == jnior_dll_calls.STATUS_RECONNECTING)
                return;

            Console.WriteLine("Jnior > " + args.Message);

            this.Invoke((MethodInvoker)delegate
            {
                if (jniorStatus.IsDisposed)
                    return;

                jniorStatus.Text = args.Message;
            });

            if (args.Status == jnior_dll_calls.STATUS_CONNECTED)
            {
                // Login to jnior box!
                LoginProperties lp = new LoginProperties(JNIOR_USER, JNIOR_PASSWORD);
                jnior_.LoginAsync(lp);
            }
            else if (args.Status == jnior_dll_calls.STATUS_CONNECTION_FAILED || args.Status == jnior_dll_calls.STATUS_DISCONNECTED)
            {
                // Reconnect right away.
                ConnectJnior();
            }
        }
예제 #20
0
        /// <summary>
        /// Function to check the Login Credentials.
        /// </summary>
        /// <param name="objLoginProp"></param>
        /// <returns>void</returns>
        /// <createdBy></createdBy>
        /// <createdOn>Apr-13,2016</createdOn>
        private async void LoginMethod()
        {
            if (IsLogining)
            {
                return;
            }

            IsLogining = true;

            await Task.Run(() =>
            {
                string userRole = string.Empty;

                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                try
                {
                    LoginProperties objLoginProp = new LoginProperties();

                    if (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrEmpty(Password))
                    {
                        objLoginProp.Username = UserName;
                        objLoginProp.Password = Password;

                        LoginResult result = _serviceInstance.ValidateLogin(objLoginProp);

                        if ((LoginStatusChanged != null) && (result.IsLoginSuccessful))

                        {
                            LoginStatusChanged(true, "Admin");
                        }


                        if (!result.IsLoginSuccessful)
                        {
                            ClsValidationPopUp.ErrMsgPassword = Resources.ErrorWrongCredential;
                            Password = string.Empty;
                            Counter++;
                            if (Counter >= 3)
                            {
                                // if 3 attempts fail then close the application.
                                Environment.Exit(0);
                            }
                        }
                        else
                        {
                            // if login validates then get the user role details
                            List <string> userRoles = new List <string>();

                            ClientContext.UserToken = result.Token;

                            if (_serviceInstance == null)
                            {
                                throw new FaultException("Some error occurred while creating the service instance. Please try again.");
                            }

                            var userDetails = _serviceInstance.GetLoggedInUserDetails(objLoginProp);

                            userRoles = userDetails.UserRoles.OrderBy(x => x.ToString()).Select(x => x.ToString()).ToList();

                            List <string> objValidRoleList = ValidRoleList();

                            Application.Current.Properties["Token"] = result.Token;

                            Application.Current.Properties["LoggedInUserNameHome"] = userDetails.FullUserName;

                            Application.Current.Properties["LoggedInUserName"] = objLoginProp.Username;

                            userRole = ValidUserRole(userRoles, objValidRoleList);

                            LoadMainModel(userRole);
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(UserName) && string.IsNullOrEmpty(Password))
                        {
                            ClsValidationPopUp.ErrMsgPassword = Resources.ErrorUsernameAndPasswordText;
                        }
                        else if (string.IsNullOrEmpty(UserName))
                        {
                            ClsValidationPopUp.ErrMsgPassword = Resources.ErrorUsernameText;
                        }
                        else if (string.IsNullOrEmpty(Password))
                        {
                            ClsValidationPopUp.ErrMsgPassword = Resources.ErrorPasswordText;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogErrorToDb(ex);
                    CommonSettings.logger.LogError(this.GetType(), ex);

                    // if the service is in a faulted state then show some message to user
                    if (_serviceInstance.State == CommunicationState.Faulted)
                    {
                        MessageBox.Show("An error has occured while accessing the service. Please close the application and try again.");
                        _serviceInstance.Abort();
                        _serviceInstance.Close();
                    }

                    if (ex != null)
                    {
                        if (ex.InnerException != null && ex.InnerException.InnerException != null)
                        {
                            if (ex.InnerException.InnerException.Message.Equals("The wait operation timed out") && ex.InnerException.Message.Equals("A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.)"))
                            {
                                MessageBox.Show("An error has occured while accessing the service. Please close the application and try again.");
                                return;
                            }
                            if (ex.InnerException.InnerException.Message.Equals("The wait operation timed out"))
                            {
                                MessageBox.Show("Connection Time out.");
                            }
                        }
                    }
                }
                finally
                {
                    IsLogining = false;
                    CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
                }
            });
        }