コード例 #1
0
        private bool loginForAlertProcessing(string userName, string password)
        {
            ZXPUserData zxpUD       = new ZXPUserData();
            int         rowCount    = 0;
            bool        isValidUser = false;

            try
            {
                string sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    sqlCmdText = "SELECT COUNT (*) FROM dbo.Users WHERE [Password] = @UPASS AND UserName = @UNAME AND isDisabled = 0";
                    rowCount   = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UNAME", userName), new SqlParameter("@UPASS", DataTransformer.PasswordHash(password))));

                    if (rowCount > 0)
                    {
                        isValidUser = true;
                    }
                    else
                    {
                        isValidUser = false;
                        throw new Exception("Invalid login.");
                    }
                    scope.Complete();
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in alertsProcessing loginForAlertProcessing(). Details: " + excep.ToString();
                ErrorLogging.LogErrorAndRedirect(2, strErr);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in alertsProcessing loginForAlertProcessing(). Details: " + ex.ToString();
                ErrorLogging.LogErrorAndRedirect(1, strErr);
            }
            finally
            {
            }
            return(isValidUser);
        }
        private bool isUserCredentialsValid(string userName, string password)
        {
            ZXPUserData zxpUD       = new ZXPUserData();
            int         rowCount    = 0;
            bool        isValidUser = false;

            try
            {
                string sqlCmdText;
                string sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                sqlCmdText = "SELECT COUNT (*) FROM dbo.Users WHERE [Password] = @UPASS AND UserName = @UNAME AND isDisabled = 0";
                rowCount   = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UPASS", DataTransformer.PasswordHash(password)),
                                                                     new SqlParameter("@UNAME", userName)));
                if (rowCount > 0)
                {
                    isValidUser = true;
                }
                else
                {
                    isValidUser = false;
                    throw new Exception("Invalid login.");
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in dataProcessingAndCleanUp isUserCredentialsValid(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in dataProcessingAndCleanUp isUserCredentialsValid(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
            finally
            {
            }
            return(isValidUser);
        }