Exemple #1
0
bool ServiceDB::GetAccountInformation( const char* username, const char* password, AccountInfo & account_info )
{
    std::string _username = username;
    std::string _escaped_username;

    DBcore::DoEscapeString(_escaped_username, _username);

    DBQueryResult res;
    if (!DBcore::RunQuery(res, "SELECT accountID, password, hash, role, online, banned, logonCount, lastLogin FROM srvAccount WHERE accountName = '%s'", _escaped_username.c_str()))
    {
        SysLog::Error( "ServiceDB", "Error in query: %s.", res.error.c_str() );
        return false;
    }

    DBResultRow row;
    if (!res.GetRow( row )) {
		// account not found, create new one if autoAccountRole is not zero (0)
		if(EVEServerConfig::account.autoAccountRole > 0) {
			uint32 accountID = CreateNewAccount( _username.c_str(), password, EVEServerConfig::account.autoAccountRole);
			if( accountID > 0 ) {
				// add new account successful, get account info again
				bool ret = GetAccountInformation(username, password, account_info);
				return ret;
			}
			else
				return false;
		}
		else
			return false;
	}

    /* when any of the text gets are NULL it will fail... I think.. */
    account_info.id         = row.GetUInt(0);

    if (!row.IsNull(1))
        account_info.password = row.GetText(1);

    if (!row.IsNull(2))
        account_info.hash   = row.GetText(2);

    account_info.name       = _escaped_username;
    account_info.role       = row.GetUInt64(3);
    account_info.online     = row.GetBool(4);
    account_info.banned     = row.GetBool(5);
    account_info.visits     = row.GetUInt(6);

    if (!row.IsNull(7))
        account_info.last_login = row.GetText(7);

    return true;
}
Exemple #2
0
static int create_new_account(void)
{
	DDPut(sd[newucstr]);
	switch (HotKey(HOT_NOYES)) {
	case 1:
		if (CreateNewAccount()) {
			clog.cl_userid = user.user_account_id;
			clog.cl_firstcall = user.user_firstcall;
			clog.cl_logon = time(0);
			if (user.user_connections == 0)
				clog.cl_flags |= CL_NEWUSER;
			clog.cl_bpsrate = bpsrate;

			getin();
			return 1;
		}
		return 0;
	case 2:
		DDPut("\n");
		return 0;
	default:
		return 1;
	}
}
Exemple #3
0
static int try_login(void)
{
	char username[300];
	int retvalue, passwdcnt;
	
	DDPut(sd[usernamestr]);
	username[0] = 0;
	
	Prompt(username, 25, 0);
	removespaces(username);
	if (!checkcarrier())
		return -1;
	if (!username[0]) {		
		DDPut("");
		return -1;
	}
	if (!strcasecmp("new", username) && 
		!(maincfg.CFG_FLAGS & (1L << 17))) {
		CreateNewAccount();
		return -1;
	}
	if (!strcasecmp("logoff", username))
		return 0;
	if (!strcasecmp("chat", username)) {
		pagesysop(0);
		return -1;
	}

	retvalue = checklogon(username);
	if (!retvalue && !(maincfg.CFG_FLAGS & (1L << 17))) {
		if (maincfg.CFG_FLAGS & (1L << 9))
			return create_new_account() ? 0 : -1;
		else {
			DDPut(sd[unknownuserstr]);
			return -1;
		}
	} else {
		if (retvalue != 1 && !(maincfg.CFG_FLAGS & (1L << 18)))
			return -1;
		for (passwdcnt = 0; passwdcnt < 3; passwdcnt++) {
			username[0] = 0;
			if (ispw() || retvalue != 1) {
				DDPut(sd[passwordstr]);
				Prompt(username, 25, PROMPT_SECRET);
			}
			if (!checkcarrier()) 
				return -1;
			if (retvalue > 0 && (!ispw() || 
				cmppasswds(username, user.user_password))) {
				if (retvalue == 2) 
					DDPut(sd[alreadyonlinestr]);
				else
					getin();
				return 0;
			} else {
				if (passwdcnt != 2)
					DDPut(sd[tryagainstr]);
				clog.cl_flags |= CL_PASSWDFAIL;
			}
		}
		if (retvalue != 2) {
			TypeFile("passwordfailure", TYPE_MAKE);
			DDPut(sd[excessivepwfailstr]);
			return 0;
		} 
	}

	return -1;
}
Exemple #4
0
bool ServiceDB::DoLogin( const char* login, const char* pass, uint32& accountID, uint32& role )
{
    if( pass[0] == '\0' )
    {
        sLog.Error( "ServiceDB", "Empty password not allowed ('%s').", login );
        return false;
    }

    if( !sDatabase.IsSafeString( login ) || !sDatabase.IsSafeString( pass ) )
    {
        sLog.Error( "ServiceDB", "Invalid characters in login or password." );
        return false;
    }
    
    DBQueryResult res;
    if( !sDatabase.RunQuery( res,
        "SELECT accountID, role, password, PASSWORD( '%s' ), MD5( '%s' ), online, banned"
        " FROM account"
        " WHERE accountName = '%s'",
        pass, pass, login ) )
    {
        sLog.Error( "ServiceDB", "Error in query: %s.", res.error.c_str() );
        return false;
    }

    DBResultRow row;
    if( res.GetRow( row ) )
    {
        if( 0 != row.GetInt( 5 ) )
        {
            sLog.Error( "ServiceDB", "Account '%s' already logged in.", login );
            return false;
        }
		if( 0 != row.GetInt( 6 ) )
		{
			sLog.Error( "ServiceDB", "Account '%s' has been banned from the server.", login);
			return false;
		}

        const std::string dbPass = row.GetText( 2 );

        if( dbPass != pass
            && dbPass != row.GetText( 3 )
            && dbPass != row.GetText( 4 ) )
        {
            sLog.Error( "ServiceDB", "Login failed for account '%s'.", login );
            return false;
        }

        accountID = row.GetUInt( 0 );
        role = row.GetUInt( 1 );

        return true;
    }
    else if( 0 == sConfig.account.autoAccountRole )
    {
        // autoAccount disabled

        sLog.Error( "ServiceDB", "Unknown account '%s'.", login );
        return false;
    }
    else
    {
        // autoAccount enabled, try to create a new account

        sLog.Log( "ServiceDB", "Creating a new account '%s' with role %u.", login, sConfig.account.autoAccountRole );

        accountID = CreateNewAccount( login, pass, sConfig.account.autoAccountRole );
        if( 0 == accountID )
        {
            sLog.Error( "ServiceDB", "Failed to create a new account." );
            return false;
        }

        role = sConfig.account.autoAccountRole;

        return true;
    }
}