Example #1
0
        /// <summary>
        /// Tries to authenticate the username and password against the given database.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="default_schema"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="database_call_back"></param>
        /// <remarks>
        /// If successful, alters the state of this object to reflect the fact the user has logged in.
        /// </remarks>
        /// <returns>
        /// Returns <b>true</b> if we are successful.
        /// </returns>
        private bool Authenticate(IDatabase database, String default_schema, String username, String password, DatabaseEventCallback database_call_back)
        {
            // If the 'user' variable is null, no one is currently logged in to this
            // connection.

            if (User != null)
                throw new Exception("Attempt to authenticate user twice");

            if (database.Context.Logger.IsInterestedIn(LogLevel.Debug)) {
                // Output the instruction to the _queries log.
                database.Context.Logger.Debug(this, String.Format("[CLIENT] [{0}][{1}] - Log in", username, host_name));
            }

            // Write debug message,
            if (Logger.IsInterestedIn(LogLevel.Info)) {
                Logger.Info(this, "Authenticate User: "******"Couldn't change to '" + default_schema + "' schema.");
                        // If we can't change to the schema then change to the APP schema
                        database_connection.SetDefaultSchema("APP");
                    }

                } finally {
                    try {
                        // Make sure we commit the connection.
                        database_connection.Commit();
                    } catch (TransactionException e) {
                        // Just issue a warning...
                        Logger.Warning(this, e);
                    } finally {
                        // Guarentee that we unluck from EXCLUSIVE
                        locker.FinishMode(LockingMode.Exclusive);
                    }
                }

            }

            // If we have a user object, then init the object,
            if (thisUser != null) {
                Init(thisUser, database_connection);
                return true;
            }

            // Otherwise, return false.
            return false;
        }