Index: src/table/settings.h
===================================================================
--- src/table/settings.h	(revision 19590)
+++ src/table/settings.h	(working copy)
@@ -635,6 +635,7 @@
 	  SDTC_STR(network.last_host,              SLE_STRB, S,  0,    "",                        STR_NULL,                                       NULL),
 	  SDTC_VAR(network.last_port,            SLE_UINT16, S,  0,     0,     0,  UINT16_MAX, 0, STR_NULL,                                       NULL),
 	 SDTC_BOOL(network.no_http_content_downloads,        S,  0, false,                        STR_NULL,                                       NULL),
         SDTC_BOOL(network.log_all,                          S, NO, false,                        STR_NULL,                                       NULL),
+	  SDTC_BOOL(network.save_password,                    S, NO, false,                        STR_NULL,                                       NULL),
 #endif /* ENABLE_NETWORK */
 
 	/*
Index: src/settings_type.h
===================================================================
--- src/settings_type.h	(revision 19590)
+++ src/settings_type.h	(working copy)
@@ -150,6 +150,7 @@
 	char   last_host[NETWORK_HOSTNAME_LENGTH];            ///< IP address of the last joined server
 	uint16 last_port;                                     ///< port of the last joined server
 	bool   no_http_content_downloads;                     ///< do not do content downloads over HTTP
	bool   log_all;                                       ///< log all commands, including those with CMD_NO_LOG?
+	bool   save_password;                                 ///< If password file is used
 #else /* ENABLE_NETWORK */
 #endif
 };
Index: src/network/network_func.h
===================================================================
--- src/network/network_func.h	(revision 19590)
+++ src/network/network_func.h	(working copy)
@@ -85,6 +85,8 @@
 void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...) WARN_FORMAT(3, 4);
 void NetworkUndrawChatMessage();
 void NetworkChatMessageDailyLoop();
+void NetworkSavePassword();
+void NetworkLoadPassword();
 
 void NetworkAfterNewGRFScan();
 
Index: src/network/network_server.cpp
===================================================================
--- src/network/network_server.cpp	(revision 19590)
+++ src/network/network_server.cpp	(working copy)
@@ -1738,6 +1738,9 @@
 	FOR_ALL_CLIENT_SOCKETS(cs) {
 		SEND_COMMAND(PACKET_SERVER_COMPANY_UPDATE)(cs);
 	}
+	if (!_password_locked && _settings_client.network.save_password) {
+		NetworkSavePassword( );
+	}
 }
 
 /**
@@ -1810,5 +1813,49 @@
 	}
 	return false;
 }
+void NetworkSavePassword( )
+{
+	static FILE *file_pointer;
+	CompanyID l_company = (CompanyID)0;
+	char password_file_name[80];
+	sprintf( password_file_name, "%u.pwd", _settings_game.game_creation.generation_seed );
+	DEBUG( net, 0, "Saving companies password to %s", password_file_name );
+	file_pointer = FioFOpenFile( password_file_name, "wb", BASE_DIR );
+	if (file_pointer != NULL) {
+		for( l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++ ) {
+			if (NetworkCompanyIsPassworded(l_company)) {
+				fwrite( _network_company_states[l_company].password, strlen(_network_company_states[l_company].password), 1, file_pointer);
+			}
+			fwrite( "\n", 1, 1, file_pointer );
+		}
+		fclose(file_pointer);
+	}
+}
 
+void NetworkLoadPassword( )
+{
+	static FILE *file_pointer;
+	char password[NETWORK_PASSWORD_LENGTH+1];
+	CompanyID l_company = (CompanyID)0;
+	char password_file_name[80];
+	sprintf( password_file_name, "%u.pwd", _settings_game.game_creation.generation_seed );
+	file_pointer = FioFOpenFile( password_file_name, "rb", BASE_DIR );
+	if (file_pointer != NULL)
+	{
+		_password_locked = true;
+		DEBUG( net, 0, "Loading password from %s", password_file_name );
+		for( l_company = (CompanyID)0; l_company < MAX_COMPANIES; l_company++ ) {
+			fgets( password, sizeof( password), file_pointer);
+			if (strlen(password)>1) {
+				strecpy(_network_company_states[l_company].password, password, lastof(_network_company_states[l_company].password));
+				NetworkServerUpdateCompanyPassworded(l_company, !StrEmpty(_network_company_states[l_company].password));
+			}
+		}
+		_password_locked = false;
+	} else {
+		DEBUG( net, 0, "Password file %s not found", password_file_name );
+	}
+}
+
+
 #endif /* ENABLE_NETWORK */
Index: src/network/network.cpp
===================================================================
--- src/network/network.cpp	(revision 19590)
+++ src/network/network.cpp	(working copy)
@@ -15,6 +15,7 @@
 
 #include "../strings_func.h"
 #include "../command_func.h"
+#include "../variables.h"
 #include "../date_func.h"
 #include "network_client.h"
 #include "network_server.h"
@@ -52,6 +53,7 @@
 bool _network_available;  ///< is network mode available?
 bool _network_dedicated;  ///< are we a dedicated server?
 bool _is_network_server;  ///< Does this client wants to be a network-server?
+bool _password_locked=false;    ///< If loading password from file.pwd
 NetworkServerGameInfo _network_game_info;
 NetworkCompanyState *_network_company_states = NULL;
 ClientID _network_own_client_id;
Index: src/network/network_internal.h
===================================================================
--- src/network/network_internal.h	(revision 19590)
+++ src/network/network_internal.h	(working copy)
@@ -129,6 +129,7 @@
 extern CompanyMask _network_company_passworded;
 
 void NetworkTCPQueryServer(NetworkAddress address);
+extern bool _password_locked;
 
 void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
 void NetworkAddServer(const char *b);
Index: src/openttd.cpp
===================================================================
--- src/openttd.cpp	(revision 19590)
+++ src/openttd.cpp	(working copy)
@@ -1017,6 +1017,10 @@
 #ifdef ENABLE_NETWORK
 				if (_network_server) {
 					snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
+					// Try to load password
+				if ( _settings_client.network.save_password ) {
+					NetworkLoadPassword( );
+					}
 				}
 #endif /* ENABLE_NETWORK */
 			}
