Esempio n. 1
0
        /// <summary>
        /// Clones GreyFoxUser object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new GreyFoxUser object reflecting the replicated GreyFoxUser object.</returns>
        public GreyFoxUser Clone()
        {
            lock (this)
            {
                GreyFoxUser clonedGreyFoxUser = new GreyFoxUser();
                clonedGreyFoxUser.iD            = iD;
                clonedGreyFoxUser.isSynced      = isSynced;
                clonedGreyFoxUser.userName      = userName;
                clonedGreyFoxUser.isDisabled    = isDisabled;
                clonedGreyFoxUser.loginDate     = loginDate;
                clonedGreyFoxUser.loginCount    = loginCount;
                clonedGreyFoxUser.loginPassword = loginPassword;
                clonedGreyFoxUser.activationID  = activationID;


                if (contact != null)
                {
                    clonedGreyFoxUser.contact = contact.Duplicate("sysGlobal_Contacts");
                }

                if (roles != null)
                {
                    clonedGreyFoxUser.roles = roles.Clone();
                }

                return(clonedGreyFoxUser);
            }
        }
Esempio n. 2
0
        public static GreyFoxUser ParseFromReader(IDataReader r, int idOffset, int dataOffset)
        {
            GreyFoxUser greyFoxUser = new GreyFoxUser();

            FillFromReader(greyFoxUser, r, idOffset, dataOffset);
            return(greyFoxUser);
        }
Esempio n. 3
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxUser.
        /// </summary>
        /// <returns> A new GreyFoxUser object reflecting the cloned GreyFoxUser object.</returns>
        /// <param name="isolation">Placeholders are used to isolate the GreyFoxUser from its children.</param>
        public GreyFoxUser Copy(bool isolation)
        {
            GreyFoxUser greyFoxUser = new GreyFoxUser();

            CopyTo(greyFoxUser, isolation);
            return(greyFoxUser);
        }
Esempio n. 4
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxUser.
        /// </summary>
        /// <returns> A new GreyFoxUser object reflecting the cloned GreyFoxUser object.</returns>
        public GreyFoxUser Copy()
        {
            GreyFoxUser greyFoxUser = new GreyFoxUser();

            CopyTo(greyFoxUser);
            return(greyFoxUser);
        }
Esempio n. 5
0
        public void ChangePassword(GreyFoxUser user, string newPassword)
        {
            string ipAddress     = "No Web Server";
            string clientDetails = "No Web Server";

            if (System.Web.HttpContext.Current != null)
            {
                ipAddress     = System.Web.HttpContext.Current.Request.UserHostAddress;
                clientDetails = System.Web.HttpContext.Current.Request.UserAgent;
            }

            // Log an event
            Amns.GreyFox.EventLog.GreyFoxEvent e =
                new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events");
            e.Category    = "Login";
            e.Description = "Lost password; username '" +
                            user.UserName + "'.<BR>" +
//				"Old Password: "******"<BR>" +
//				"New Password: "******"<BR>" +
                            "IP Address: " + ipAddress + "<BR>" +
                            "Client: " + clientDetails;
            e.EventDate = DateTime.Now;
            e.EventID   = 25201;
            e.Source    = "AUDITOR";
            e.Type      = 105;
            e.User      = user;
            e.Save();

            user.LoginPassword = newPassword;
            user.Encrypt();
            user.Save();
        }
Esempio n. 6
0
        public static GreyFoxUser NewPlaceHolder(int iD)
        {
            GreyFoxUser greyFoxUser = new GreyFoxUser();

            greyFoxUser.iD            = iD;
            greyFoxUser.isPlaceHolder = true;
            greyFoxUser.isSynced      = true;
            return(greyFoxUser);
        }
Esempio n. 7
0
        public bool Equals(GreyFoxUser greyFoxUser)
        {
            if (greyFoxUser == null)
            {
                return(false);
            }

            return(this.iD == greyFoxUser.iD);
        }
Esempio n. 8
0
        public void Remove(GreyFoxUser value)
        {
            OnCollectionChanged(EventArgs.Empty);
            int index = IndexOf(value);

            if (index == -1)
            {
                throw(new Exception("GreyFoxUser not found in collection."));
            }
            RemoveAt(index);
        }
Esempio n. 9
0
        /// <summary>
        /// Duplicates GreyFoxUser object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new GreyFoxUser object reflecting the replicated GreyFoxUser object.</returns>
        public GreyFoxUser Duplicate()
        {
            lock (this)
            {
                GreyFoxUser clonedGreyFoxUser = this.Clone();

                // Insert must be called after children are replicated!
                clonedGreyFoxUser.iD       = GreyFoxUserManager._insert(clonedGreyFoxUser);
                clonedGreyFoxUser.isSynced = true;
                return(clonedGreyFoxUser);
            }
        }
Esempio n. 10
0
 public int IndexOf(GreyFoxUser value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (GreyFoxUserArray[x].Equals(value))
             {
                 return(x);
             }
         }
         return(-1);
     }
 }
Esempio n. 11
0
        internal static int _update(GreyFoxUser greyFoxUser)
        {
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            dbCommand = database.GetSqlStringCommand("UPDATE sysGlobal_Users SET UserName=@UserName," +
                                                     "IsDisabled=@IsDisabled," +
                                                     "LoginDate=@LoginDate," +
                                                     "LoginCount=@LoginCount," +
                                                     "LoginPassword=@LoginPassword," +
                                                     "ContactID=@ContactID," +
                                                     "ActivationID=@ActivationID WHERE GreyFoxUserID=@GreyFoxUserID;");

            fillParameters(database, dbCommand, greyFoxUser);
            database.AddInParameter(dbCommand, "GreyFoxUserID", DbType.Int32, greyFoxUser.iD);
            // Abandon remaining updates if no rows have been updated by returning false immediately.
            if (database.ExecuteNonQuery(dbCommand) == 0)
            {
                return(-1);
            }

            if (greyFoxUser.roles != null)
            {
                // Delete child relationships for Roles.
                dbCommand = database.GetSqlStringCommand("DELETE  FROM sysGlobal_UsersChildren_Roles WHERE GreyFoxUserID=@GreyFoxUserID;");
                database.AddInParameter(dbCommand, "@GreyFoxUserID", DbType.Int32, greyFoxUser.iD);
                database.ExecuteNonQuery(dbCommand);

                // Save child relationships for Roles.
                dbCommand = database.GetSqlStringCommand("INSERT INTO sysGlobal_UsersChildren_Roles (GreyFoxUserID, GreyFoxRoleID) VALUES (@GreyFoxUserID, @GreyFoxRoleID);");
                database.AddInParameter(dbCommand, "@GreyFoxUserID", DbType.Int32, greyFoxUser.iD);
                database.AddInParameter(dbCommand, "@GreyFoxRoleID", DbType.Int32);
                foreach (GreyFoxRole greyFoxRole in greyFoxUser.roles)
                {
                    dbCommand.Parameters["@GreyFoxRoleID"].Value = greyFoxRole.ID;
                    database.ExecuteNonQuery(dbCommand);
                }
            }

            // Store greyFoxUser in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxUser);
            }

            return(greyFoxUser.iD);
        }
Esempio n. 12
0
        internal static bool _fill(GreyFoxUser greyFoxUser)
        {
            // Clone item from cache.
            if (cacheEnabled)
            {
                object cachedObject = cacheFind(greyFoxUser.iD);
                if (cachedObject != null)
                {
                    ((GreyFoxUser)cachedObject).CopyTo(greyFoxUser, true);
                    return(greyFoxUser.isSynced);
                }
            }

            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;

            query = new StringBuilder("SELECT ");
            query.Append(string.Join(",", InnerJoinFields));
            query.Append(" FROM sysGlobal_Users WHERE GreyFoxUserID=");
            query.Append(greyFoxUser.iD);
            query.Append(";");

            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
            IDataReader r = database.ExecuteReader(dbCommand);

            if (!r.Read())
            {
                throw(new Exception(string.Format("Cannot find GreyFoxUserID '{0}'.",
                                                  greyFoxUser.iD)));
            }

            FillFromReader(greyFoxUser, r, 0, 1);

            // Microsoft DAAB still needs to have the reader closed.
            r.Close();

            // Store greyFoxUser in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxUser);
            }

            return(true);
        }
Esempio n. 13
0
 public int Add(GreyFoxUser value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > GreyFoxUserArray.GetUpperBound(0) + 1)
         {
             GreyFoxUser[] tempGreyFoxUserArray = new GreyFoxUser[count * 2];
             Array.Copy(GreyFoxUserArray, tempGreyFoxUserArray, count - 1);
             GreyFoxUserArray = tempGreyFoxUserArray;
         }
         GreyFoxUserArray[count - 1] = value;
     }
     return(count - 1);
 }
Esempio n. 14
0
        /// <summary>
        /// Fills the {0} from a OleIDataReader.
        /// </summary>
        public static void FillFromReader(GreyFoxUser greyFoxUser, IDataReader r, int idOffset, int dataOffset)
        {
            greyFoxUser.iD            = r.GetInt32(idOffset);
            greyFoxUser.isSynced      = true;
            greyFoxUser.isPlaceHolder = false;

            greyFoxUser.userName = r.GetString(0 + dataOffset);
            if (!r.IsDBNull(1 + dataOffset))
            {
                greyFoxUser.isDisabled = r.GetBoolean(1 + dataOffset);
            }
            if (!r.IsDBNull(2 + dataOffset))
            {
                greyFoxUser.loginDate = r.GetDateTime(2 + dataOffset);
            }
            else
            {
                greyFoxUser.loginDate = DateTime.MinValue;
            }
            if (!r.IsDBNull(3 + dataOffset))
            {
                greyFoxUser.loginCount = r.GetInt32(3 + dataOffset);
            }
            if (!r.IsDBNull(4 + dataOffset))
            {
                greyFoxUser.loginPassword = r.GetString(4 + dataOffset);
            }
            else
            {
                greyFoxUser.loginPassword = null;
            }
            if (!r.IsDBNull(5 + dataOffset) && r.GetInt32(5 + dataOffset) > 0)
            {
                greyFoxUser.contact = GreyFoxContact.NewPlaceHolder("sysGlobal_Contacts", r.GetInt32(5 + dataOffset));
            }
            if (!r.IsDBNull(6 + dataOffset))
            {
                greyFoxUser.activationID = r.GetString(6 + dataOffset);
            }
            else
            {
                greyFoxUser.activationID = string.Empty;
            }
        }
Esempio n. 15
0
        public static void FillRoles(GreyFoxUser greyFoxUser)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            s = new StringBuilder("SELECT GreyFoxRoleID FROM sysGlobal_UsersChildren_Roles ");
            s.Append("WHERE GreyFoxUserID=");
            s.Append(greyFoxUser.iD);
            s.Append(";");

            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(s.ToString());
            r         = database.ExecuteReader(dbCommand);

            GreyFoxRoleCollection roles;

            if (greyFoxUser.roles != null)
            {
                roles = greyFoxUser.roles;
                roles.Clear();
            }
            else
            {
                roles             = new GreyFoxRoleCollection();
                greyFoxUser.roles = roles;
            }

            while (r.Read())
            {
                roles.Add(GreyFoxRole.NewPlaceHolder(r.GetInt32(0)));
            }

            greyFoxUser.Roles = roles;
            // Store GreyFoxUser in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxUser);
            }
        }
Esempio n. 16
0
        private static void fillParameters(Database database, DbCommand dbCommand, GreyFoxUser greyFoxUser)
        {
            #region Default

            addParameter(database, dbCommand, "@UserName", DbType.String, greyFoxUser.userName);
            addParameter(database, dbCommand, "@IsDisabled", DbType.Boolean, greyFoxUser.isDisabled);
            addParameter(database, dbCommand, "@LoginDate", DbType.Date, greyFoxUser.loginDate);
            addParameter(database, dbCommand, "@LoginCount", DbType.Int32, greyFoxUser.loginCount);
            addParameter(database, dbCommand, "@LoginPassword", DbType.String, greyFoxUser.loginPassword);
            if (greyFoxUser.contact == null)
            {
                addParameter(database, dbCommand, "@ContactID", DbType.Int32, DBNull.Value);
            }
            else
            {
                addParameter(database, dbCommand, "@ContactID", DbType.Int32, greyFoxUser.contact.ID);
            }
            addParameter(database, dbCommand, "@ActivationID", DbType.String, greyFoxUser.activationID);

            #endregion
        }
Esempio n. 17
0
 public void Insert(int index, GreyFoxUser value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > GreyFoxUserArray.GetUpperBound(0) + 1)
         {
             GreyFoxUser[] tempGreyFoxUserArray = new GreyFoxUser[count * 2];
             Array.Copy(GreyFoxUserArray, tempGreyFoxUserArray, count - 1);
             GreyFoxUserArray = tempGreyFoxUserArray;
         }
         for (int x = index + 1; x == count - 2; x++)
         {
             GreyFoxUserArray[x] = GreyFoxUserArray[x - 1];
         }
         GreyFoxUserArray[index] = value;
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Deep copies the current GreyFoxUser to another instance of GreyFoxUser.
 /// </summary>
 /// <param name="GreyFoxUser">The GreyFoxUser to copy to.</param>
 /// <param name="isolation">Placeholders are used to isolate the GreyFoxUser from its children.</param>
 public void CopyTo(GreyFoxUser greyFoxUser, bool isolation)
 {
     lock (this)
     {
         greyFoxUser.iD            = iD;
         greyFoxUser.isPlaceHolder = isPlaceHolder;
         greyFoxUser.isSynced      = isSynced;
         greyFoxUser.userName      = userName;
         greyFoxUser.isDisabled    = isDisabled;
         greyFoxUser.loginDate     = loginDate;
         greyFoxUser.loginCount    = loginCount;
         greyFoxUser.loginPassword = loginPassword;
         if (contact != null)
         {
             if (isolation)
             {
                 greyFoxUser.contact = contact.NewPlaceHolder();
             }
             else
             {
                 greyFoxUser.contact = contact.Copy(false);
             }
         }
         if (roles != null)
         {
             if (isolation)
             {
                 greyFoxUser.roles = roles.Copy(true);
             }
             else
             {
                 greyFoxUser.roles = roles.Copy(false);
             }
         }
         greyFoxUser.activationID = activationID;
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(GreyFoxUser greyFoxUser)
 {
     return(this.iD - greyFoxUser.iD);
 }
Esempio n. 20
0
        private static void cacheStore(GreyFoxUser greyFoxUser)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add("sysGlobal_Users_" + greyFoxUser.iD.ToString(), greyFoxUser);
        }
Esempio n. 21
0
 /// <summary>
 /// Deep copies the current GreyFoxUser to another instance of GreyFoxUser.
 /// This method does not provide isolated copies; use overriden method for this feature.
 /// </summary>
 /// <param name="GreyFoxUser">The GreyFoxUser to copy to.</param>
 public void CopyTo(GreyFoxUser greyFoxUser)
 {
     CopyTo(greyFoxUser, false);
 }
Esempio n. 22
0
        public GreyFoxUserCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxUserFlags[] optionFlags)
        {
            StringBuilder         query;
            Database              database;
            DbCommand             dbCommand;
            IDataReader           r;
            GreyFoxUserCollection greyFoxUserCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("GreyFoxUser.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int contactOffset = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxUserFlags.Contact:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Contact.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        contactOffset   = innerJoinOffset;
                        innerJoinOffset = contactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("sysGlobal_Users AS GreyFoxUser");
            }
            else
            {
                query.Append(" FROM sysGlobal_Users AS GreyFoxUser");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxUserFlags.Contact:
                        query.Append(" LEFT JOIN sysGlobal_Contacts AS Contact ON GreyFoxUser.ContactID = Contact.GreyFoxContactID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            greyFoxUserCollection = new GreyFoxUserCollection();

            while (r.Read())
            {
                GreyFoxUser greyFoxUser = ParseFromReader(r, 0, 1);

                // Fill Contact
                if (contactOffset != -1 && !r.IsDBNull(contactOffset))
                {
                    GreyFoxContactManager.FillFromReader(greyFoxUser.contact, "sysGlobal_Contacts", r, contactOffset, contactOffset + 1);
                }

                greyFoxUserCollection.Add(greyFoxUser);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            return(greyFoxUserCollection);
        }
Esempio n. 23
0
        /// <summary>
        /// Compares the object's ID to another object's ID.
        /// </summary>
        int IComparable.CompareTo(object obj)
        {
            GreyFoxUser greyFoxUser = (GreyFoxUser)obj;

            return(this.iD - greyFoxUser.iD);
        }
Esempio n. 24
0
        /// <summary>
        /// Inserts a GreyFoxUser into the database. All children should have been
        /// saved to the database before insertion. New children will not be
        /// related to this object in the database.
        /// </summary>
        /// <param name="_GreyFoxUser">The GreyFoxUser to insert into the database.</param>
        internal static int _insert(GreyFoxUser greyFoxUser)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO sysGlobal_Users " +
                    "(" +
                    "UserName," +
                    "IsDisabled," +
                    "LoginDate," +
                    "LoginCount," +
                    "LoginPassword," +
                    "ContactID," +
                    "ActivationID) VALUES (" +
                    "@UserName," +
                    "@IsDisabled," +
                    "@LoginDate," +
                    "@LoginCount," +
                    "@LoginPassword," +
                    "@ContactID," +
                    "@ActivationID);";

            if (database.ConnectionStringWithoutCredentials.StartsWith("provider=microsoft.jet.oledb.4.0"))
            {
                // Microsoft Access
                // Connection must remain open for IDENTITY to return correct value,
                // therefore use the dbCommand object's Connection directly to control
                // connection state.
                dbCommand = database.GetSqlStringCommand(query);
                fillParameters(database, dbCommand, greyFoxUser);
                dbCommand.Connection = database.CreateConnection();
                dbCommand.Connection.Open();
                dbCommand.ExecuteNonQuery();
                dbCommand.CommandText = "SELECT @@IDENTITY AS LastID";
                id = (int)dbCommand.ExecuteScalar();
                dbCommand.Connection.Close();
            }
            else
            {
                //// Microsoft SQL Server
                dbCommand = database.GetSqlStringCommand(query + " SELECT @LastID = SCOPE_IDENTITY();");
                fillParameters(database, dbCommand, greyFoxUser);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }

            // Save child relationships for Roles.
            if (greyFoxUser.roles != null)
            {
                dbCommand = database.GetSqlStringCommand("INSERT INTO sysGlobal_UsersChildren_Roles " +
                                                         "(GreyFoxUserID, GreyFoxRoleID)" +
                                                         " VALUES (@GreyFoxUserID, @GreyFoxRoleID);");
                addParameter(database, dbCommand, "@GreyFoxUserID", DbType.Int32);
                addParameter(database, dbCommand, "@GreyFoxRoleID", DbType.Int32);
                foreach (GreyFoxRole item in greyFoxUser.roles)
                {
                    dbCommand.Parameters["@GreyFoxUserID"].Value = id;
                    dbCommand.Parameters["@GreyFoxRoleID"].Value = item.ID;
                    database.ExecuteNonQuery(dbCommand);
                }
            }
            // Store greyFoxUser in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxUser);
            }
            return(id);
        }
Esempio n. 25
0
        /// <summary>
        /// Logs in a user to the system and optionally logs success and failures to the audit log.
        /// </summary>
        /// <returns>Returns associated user if one exists, or returns null if no user exists.</returns>
        public GreyFoxUser Login(string username, string password, string ipAddress,
                                 string clientDetails, bool logSuccess, bool logFailure)
        {
            GreyFoxUser user = null;

            try
            {
                user = GetByUsername(username);
            }
            catch
            {
                if (logFailure)
                {
                    Amns.GreyFox.EventLog.GreyFoxEvent e =
                        new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events");
                    e.Category    = "Login";
                    e.Description = "Login failure; invalid username '" +
                                    username + "'.<BR>" +
                                    "IP Address: " + ipAddress + "<BR>" +
                                    "Client: " + clientDetails;
                    e.EventDate = DateTime.Now;
                    e.EventID   = 25104;
                    e.Source    = "AUDITOR";
                    e.Type      = 105;
                    e.User      = null;
                    e.Save();
                }

                throw(new Exception("Login failure; invalid username."));
            }

            if (GreyFoxPassword.DecodePassword(user.loginPassword).ToLower() !=
                password.ToLower())
            {
                if (logFailure)
                {
                    Amns.GreyFox.EventLog.GreyFoxEvent e =
                        new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events");
                    e.Category    = "Login";
                    e.Description = "Login failure; incorrect password for '" + username + "'.<BR>" +
                                    "Password used '" + password + "'.<BR>" +
                                    "IP Address: " + ipAddress + "<BR>" +
                                    "Client: " + clientDetails;
                    e.EventDate = DateTime.Now;
                    e.EventID   = 25105;
                    e.Source    = "AUDITOR";
                    e.Type      = 105;
                    e.User      = user;
                    e.Save();

                    user.LoginCount++;
                    user.Save();

                    // Delay the user 15 seconds if he's tried in the last 24 hours
                    if (user.LoginCount == 4)
                    {
                        System.Threading.Thread.Sleep(15 * 1000);
                    }
                    // Delay the user 15 seconds + 5 second increments
                    else if (user.LoginCount > 5 & user.LoginCount <= 11)
                    {
                        System.Threading.Thread.Sleep(5 * 1000 * user.LoginCount + 15 * 1000);
                    }
                    // Delay the user 15 seconds + 10 second increments
                    else if (user.LoginCount > 11)
                    {
                        System.Threading.Thread.Sleep(15 * 1000 * user.LoginCount + 15 * 1000);
                    }
                }
                throw(new Exception("Login failure; incorrect password."));
            }
            if (user.isDisabled)
            {
                if (logFailure)
                {
                    Amns.GreyFox.EventLog.GreyFoxEvent e =
                        new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events");
                    e.Category    = "Login";
                    e.Description = "Login failure; '" + username + "' disabled.<BR>" +
                                    "IP Address: " + ipAddress + "<BR>" +
                                    "Client: " + clientDetails;
                    e.EventDate = DateTime.Now;
                    e.EventID   = 25110;
                    e.Source    = "AUDITOR";
                    e.Type      = 105;
                    e.User      = user;
                    e.Save();
                }

                throw(new Exception("Login failure; user disabled."));
            }

            if (logSuccess)
            {
                Amns.GreyFox.EventLog.GreyFoxEvent e =
                    new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events");
                e.Category    = "Login";
                e.Description = "Login success; '" + username + "'.<BR>" +
                                "IP Address: " + ipAddress + "<BR>" +
                                "Client: " + clientDetails;
                e.EventDate = DateTime.Now;
                e.EventID   = 25001;
                e.Source    = "AUDITOR";
                e.Type      = 100;
                e.User      = user;
                e.Save();

                // Delay the user 15 seconds if he's tried in the last 24 hours
                if (user.LoginCount == 4)
                {
                    System.Threading.Thread.Sleep(15 * 1000);
                }
                // Delay the user 15 seconds + 5 second increments
                else if (user.LoginCount > 5 & user.LoginCount <= 11)
                {
                    System.Threading.Thread.Sleep(5 * 1000 * user.LoginCount + 15 * 1000);
                }
                // Delay the user 15 seconds + 10 second increments
                else if (user.LoginCount > 11)
                {
                    System.Threading.Thread.Sleep(15 * 1000 * user.LoginCount + 15 * 1000);
                }
            }

            user.loginCount = 1;
            user.loginDate  = DateTime.Now;
            user.isSynced   = false;
            user.Save();

            return(user);
        }
Esempio n. 26
0
 public bool Contains(GreyFoxUser value)
 {
     return(IndexOf(value) != -1);
 }