示例#1
0
        internal static void FillByUserName(User user)
        {
            // #1- Logger variables
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
            string methodName = stackFrame.GetMethod().Name;

            string query = "SELECT id, groupName,password,passwordDate,deleted,disabled,dateCreated,dateDeleted,dateDisabled FROM incuser WHERE userName = @userName";
            Hashtable param = new Hashtable();
            param.Add("@userName", user.userName);

            // #2- Logger pre query
            Logger.LogDebug("(%s) (%s) -- Ejecuta query para obtener todos los folios. QUERY: %s", className, methodName, query);

            using (DataTable dt = ExecuteDataTableQuery(query, param))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    // #3- Logger post query
                    Logger.LogDebug("Row count: %s", dt.Rows.Count.ToString());

                    DataRow row = dt.Rows[0];
                    user.userName = user.userName;
                    user.id = (row["id"] != DBNull.Value) ? row["id"].ToString() : string.Empty;
                    user.groupName = (row["groupName"] != DBNull.Value) ? row["groupName"].ToString() : string.Empty;
                    user.password = (row["password"] != DBNull.Value) ? row["password"].ToString() : string.Empty;
                    user.passwordDate = (row["passwordDate"] != DBNull.Value) ? DateTime.Parse(row["passwordDate"].ToString()) : DateTime.Now;
                    user.deleted = (row["deleted"] != DBNull.Value) ? int.Parse(row["deleted"].ToString()) : 0;
                    user.disabled = (row["disabled"] != DBNull.Value) ? int.Parse(row["disabled"].ToString()) : 0;
                    user.dateCreated = (row["dateCreated"] != DBNull.Value) ? DateTime.Parse(row["dateCreated"].ToString()) : DateTime.Now;
                    user.dateDeleted = (row["dateDeleted"] != DBNull.Value) ? DateTime.Parse(row["dateDeleted"].ToString()) : DateTime.Now;
                    user.dateDisabled = (row["dateDisabled"] != DBNull.Value) ? DateTime.Parse(row["dateDisabled"].ToString()) : DateTime.Now;
                }
            }
        }
        public string CheckLogin(string username, string password, bool isPasswordInput_hashed, bool isTokenLogin = false)
        {
            string result = string.Empty;
            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                User user = new User("", username);
                if (user != null && !string.IsNullOrWhiteSpace(user.id) && user.deleted != 1 && user.disabled != 1)
                {
                    if (!isTokenLogin)
                    {
                        // If is hashed in DB, then get my input password hashed
                        string password_hash = password;
                        if (!isPasswordInput_hashed)
                        {
                            password_hash = BCrypt.HashPassword(password, user.password);
                        }

                        if (user.password.Equals(password_hash))
                        {
                            result = user.id;
                        }
                    }
                    else
                    {
                        result = user.id;
                    }
                }
            }
            return result;
        }
示例#3
0
        private void Perform_login(string username, string password, bool isPasswordInput_hashed = false, bool isTokenLogin = false)
        {
            if (!string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(password))
            {
                bool ok = false;
                try
                {
                    string userID = Global.GlobalMethods.CheckLogin(username, password, isPasswordInput_hashed, isTokenLogin);
                    if (!string.IsNullOrWhiteSpace(userID))
                    {
                        User user = new User(userID, "");
                        if (user != null)
                        {
                            ok = true;
                            Session["UserID"] = user.id;
                            Session["UserName"] = user.userName;

                            string returnURL = "Dashboard.aspx";
                            string query_string = Request.QueryString["folioID"];
                            if (!string.IsNullOrWhiteSpace(query_string))
                            {
                                returnURL = "Dashboard.aspx?folioID=" + query_string;
                            }

                            Response.Redirect(returnURL, false);
                        }
                    }
                    if (!ok)
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "ShowErrorMessage", "ShowErrorMessage('" + 2 + "');", true);
                    }
                }
                catch (Exception e)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "ShowErrorMessage", "ShowErrorMessage('" + 3 + "');", true);

                    // #1- Logger variables
                    System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
                    string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                    string methodName = stackFrame.GetMethod().Name;

                    // #2- Logger exception
                    Logger.LogError("(%s) (%s) -- Excepcion. Haciendo login. ERROR: %s", className, methodName, e.Message);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "ShowErrorMessage", "ShowErrorMessage('" + 1 + "');", true);
            }
        }
示例#4
0
        public static int ConfirmRemoveElement(string userID, string password_input, int tapeID, bool isExtra)
        {
            int result = 0;
            /* 0 - Invalid password
             * 1 - OK
             * 2 - DB Error
             * */
            if (!string.IsNullOrWhiteSpace(userID) && !string.IsNullOrWhiteSpace(password_input))
            {
                // #1- Logger variables
                System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
                string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                string methodName = stackFrame.GetMethod().Name;

                // #1-2- Params register
                Logger.LogDebug("(%s) (%s) -- Info WebMethod. Parametros recibidos: " + userID + ", " + password_input + ", " + tapeID.ToString() + ", " + isExtra.ToString(), className, methodName);

                User user = new User(userID, "");
                if (user != null)
                {
                    string uID = Global.GlobalMethods.CheckLogin(user.userName, password_input);
                    {
                        if (!string.IsNullOrWhiteSpace(uID))
                        {
                            result = 1; // OK
                        }
                    }
                }

                if (result == 1)
                {
                    result = Global.GlobalMethods.RemoveTimelineElement(tapeID, isExtra) ? 1 : 2;
                }
            }
            return result;
        }