diff --git a/.gitattributes b/.gitattributes
index 812f7c78807f5fcd8f366378bc92d198c41da603..25dcbcb8f072841e75dd4264fb60b6e75dddb0ec 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -130,7 +130,12 @@ testfont binary
 /src/modules/Pipe/pipe.c foreign_ident
 /src/modules/Postgres/Makefile.in foreign_ident
 /src/modules/Postgres/configure.in foreign_ident
+/src/modules/Postgres/extras/test_notify.pike foreign_ident
+/src/modules/Postgres/extras/test_schema.pike foreign_ident
+/src/modules/Postgres/pg_types.h foreign_ident
 /src/modules/Postgres/pgres_config.h.in foreign_ident
+/src/modules/Postgres/pgresult.c foreign_ident
+/src/modules/Postgres/pgresult.h foreign_ident
 /src/modules/Postgres/postgres.c foreign_ident
 /src/modules/Postgres/version.h foreign_ident
 /src/modules/Regexp/acconfig.h foreign_ident
diff --git a/src/modules/Postgres/configure.in b/src/modules/Postgres/configure.in
index e8337a7f4f2264442da54247d5e4351e9516a9e8..40ef9730f76b0375bb42256a157436507141fe18 100644
--- a/src/modules/Postgres/configure.in
+++ b/src/modules/Postgres/configure.in
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.6 1998/07/15 18:48:22 grubba Exp $
+dnl $Id: configure.in,v 1.7 1998/08/25 13:27:12 grubba Exp $
 dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
 
 AC_INIT(postgres.c)
@@ -136,6 +136,10 @@ dnl last check, just to be sure
 		fi
 		AC_CHECK_LIB(pq,PQclear)
 	fi
+	AC_CHECK_FUNCS(PQsetdbLogin)
+	if test x$ac_cv_func_PQsetdbLogin = xno; then
+		AC_MSG_WARN(No Login-related functions, username and password will be silently ignored)
+	fi
 fi
 
 if test  x$ac_cv_lib_pq_PQclear != xyes; then
diff --git a/src/modules/Postgres/extras/test_notify.pike b/src/modules/Postgres/extras/test_notify.pike
index 61c5e4e73b992fd65c787a367c1514e01c677313..95607ebf0dec6cd1962331b35bd15633ee085ca0 100644
--- a/src/modules/Postgres/extras/test_notify.pike
+++ b/src/modules/Postgres/extras/test_notify.pike
@@ -1,5 +1,7 @@
 #include <postgres.h>
-/* This simple program connects to the template1 database "template1"
+/* $Id: test_notify.pike,v 1.2 1998/08/25 13:27:19 grubba Exp $
+ *
+ * This simple program connects to the template1 database "template1"
  * (it comes default with postgres95) and sits there waiting for
  * someone to issue a notify sql command on a table named "prova".
  * When this happens, it prints a message and exits.
diff --git a/src/modules/Postgres/extras/test_schema.pike b/src/modules/Postgres/extras/test_schema.pike
index 930b36236d719198c44739267a6854eba66becc0..6fca8d215fd9b5b11b05285b4d2f2e37ffb0f502 100644
--- a/src/modules/Postgres/extras/test_schema.pike
+++ b/src/modules/Postgres/extras/test_schema.pike
@@ -1,3 +1,5 @@
+// $Id: test_schema.pike,v 1.2 1998/08/25 13:27:20 grubba Exp $
+
 //#include "postgres.h"
 #include <sql.h>
 
diff --git a/src/modules/Postgres/pg_types.h b/src/modules/Postgres/pg_types.h
index 4fff04bcde540aa015a178018e9d9aeaae5db311..955af6852449a49abeebb9e071ff7c3f37406aa4 100644
--- a/src/modules/Postgres/pg_types.h
+++ b/src/modules/Postgres/pg_types.h
@@ -1,3 +1,4 @@
+/* $Id: pg_types.h,v 1.3 1998/08/25 13:27:14 grubba Exp $ */
 #ifndef _PG_TYPES_H_
 #define _PG_TYPES_H_
 
diff --git a/src/modules/Postgres/pgres_config.h.in b/src/modules/Postgres/pgres_config.h.in
index b3564808a53c355fb445823490a5adcb88c86eba..3cb6df15e41c4cd163155fdd34fdc8025fd9f7f1 100644
--- a/src/modules/Postgres/pgres_config.h.in
+++ b/src/modules/Postgres/pgres_config.h.in
@@ -1,9 +1,14 @@
-/* $Id: pgres_config.h.in,v 1.2 1997/11/25 20:57:57 grubba Exp $ */
+/* $Id: pgres_config.h.in,v 1.3 1998/08/25 13:27:15 grubba Exp $ */
 #undef STDC_HEADERS
 
+/* Define if you have the <postgres.h> header file.  */
 #undef HAVE_POSTGRES_H
+/* Define if you have the <libpq-fe.h> header file.  */
 #undef HAVE_LIBPQ_FE_H
+/* Define if you have the pq library (-lpq).  */
 #undef HAVE_LIBPQ
+/* Define if you have the PQsetdbLogin function.  */
+#undef HAVE_PQSETDBLOGIN
 
 
 /* End of autoconfigurable section */
diff --git a/src/modules/Postgres/pgresult.c b/src/modules/Postgres/pgresult.c
index ae277a3296ed5854260bebd1a16bd2770042aae2..659e2865c9caeb50e6081aa2297f71080cc942e1 100644
--- a/src/modules/Postgres/pgresult.c
+++ b/src/modules/Postgres/pgresult.c
@@ -1,4 +1,6 @@
 /*
+ * $Id: pgresult.c,v 1.6 1998/08/25 13:27:16 grubba Exp $
+ *
  * Postgres95 support for pike/0.5 and up
  *
  * (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
@@ -32,7 +34,6 @@
  */
 
 #include "global.h"
-
 #include "pgres_config.h"
 #ifdef HAVE_POSTGRES
 
@@ -62,6 +63,8 @@
 #include "builtin_functions.h"
 #include "module_support.h"
 
+RCSID("$Id: pgresult.c,v 1.6 1998/08/25 13:27:16 grubba Exp $");
+
 #ifdef _REENTRANT
 MUTEX_T pike_postgres_result_mutex;
 #define PQ_LOCK() mt_lock(&pike_postgres_mutex)
@@ -230,7 +233,11 @@ void pgresult_init (void)
 			OPT_EXTERNAL_DEPEND|OPT_RETURN);
 	pgresult_program=end_program();
 	add_program_constant("postgres_result",pgresult_program,0);
-	pgresult_program->refs++;
+	add_ref(pgresult_program);
 }
 
+#else
+
+static int place_holder;	/* Keep the compiler happy */
+
 #endif
diff --git a/src/modules/Postgres/pgresult.h b/src/modules/Postgres/pgresult.h
index cfd6bf1fd3b6b1ebc65b842b2d17245db19752b3..e62facd3c76db7985d2b863a3aaedc3ec696237e 100644
--- a/src/modules/Postgres/pgresult.h
+++ b/src/modules/Postgres/pgresult.h
@@ -1 +1,2 @@
+/* $Id: pgresult.h,v 1.2 1998/08/25 13:27:17 grubba Exp $ */
 void pgresult_init(void);
diff --git a/src/modules/Postgres/postgres.c b/src/modules/Postgres/postgres.c
index dae5816d0fd7555b8e39f9e3be7c4367a4ac51cf..dc0290a5eaf586e11e04d47df67cd3caa31e4c43 100644
--- a/src/modules/Postgres/postgres.c
+++ b/src/modules/Postgres/postgres.c
@@ -8,7 +8,6 @@
  */
 
 #include "global.h"
-
 #include "pgres_config.h"
 #ifdef HAVE_POSTGRES
 
@@ -63,7 +62,7 @@ static void pgdebug (char * a, ...) {}
 
 struct program * postgres_program;
 
-RCSID("$Id: postgres.c,v 1.7 1998/07/15 18:45:52 grubba Exp $");
+RCSID("$Id: postgres.c,v 1.8 1998/08/25 13:27:18 grubba Exp $");
 
 #define THIS ((struct pgres_object_data *) fp->current_storage)
 
@@ -107,14 +106,20 @@ static void pgres_destroy (struct object * o)
 	}
 }
 
+/* create (host,database,username,password,port) */
 static void f_create (INT32 args)
 {
-	char * host=NULL, *db=NULL, *port=NULL;
+        /*port will be used as a string with a sprintf()*/
+	char * host=NULL, *db=NULL, *user=NULL, *pass=NULL, *port=NULL;
 	PGconn * conn;
 
 	check_all_args("postgres->create",args,
-			BIT_STRING|BIT_VOID,BIT_STRING|BIT_VOID,
-			BIT_INT|BIT_VOID,0);
+			BIT_STRING|BIT_VOID,
+		        BIT_STRING|BIT_VOID,
+			BIT_STRING|BIT_VOID,
+		        BIT_STRING|BIT_VOID,
+			BIT_INT|BIT_VOID,
+		        0);
 
 	if (THIS->dblink) {
 		conn=THIS->dblink;
@@ -124,6 +129,35 @@ static void f_create (INT32 args)
 		PQ_UNLOCK();
 		THREADS_DISALLOW();
 	}
+
+	/*no break;'s here, it's intentional*/
+	switch(args) {
+		default:
+		case 5:
+			if (sp[2-args].type==T_INT &&  /*this check is maybe redundant*/
+					sp[2-args].u.integer <=65535 && 
+			    		sp[2-args].u.integer >= 0) {
+				if (sp[2-args].u.integer>0) {
+					port=xalloc(10*sizeof(char)); /*we only need 6, we just checked.*/
+					sprintf(port,"%d",sp[2-args].u.integer);
+				}
+			}
+		case 4:
+			if (sp[3-args].type==T_STRING && sp[3-args].u.string->len)
+				pass=sp[3-args].u.string->str;
+		case 3:
+			if (sp[2-args].type==T_STRING && sp[2-args].u.string->len)
+				user=sp[2-args].u.string->str;
+		case 2:
+			if (sp[1-args].type==T_STRING && sp[1-args].u.string->len)
+				db=sp[1-args].u.string->str;
+		case 1:
+			if(sp[-args].type==T_STRING && sp[-args].u.string->len)
+				host=sp[-args].u.string->str;
+		case 0:
+	}
+#if 0
+	/* Old arguments-checking code */
 	if (args>=1)
 		if(sp[-args].type==T_STRING && sp[-args].u.string->len)
 			host=sp[-args].u.string->str;
@@ -144,11 +178,18 @@ static void f_create (INT32 args)
 			}
 		}
 		else
-			error ("You must specify a TCP/IP port number as argument 5 to Sql.postgres->create().\n");
+			error ("You must specify a TCP/IP port number as argument 5 "
+					"to Sql.postgres->create().\n");
+#endif
+	pgdebug("f_create(host=%s, port=%s, db=%s, user=%s, pass=%s).\n",
+			host,port,db,user,pass);
 	THREADS_ALLOW();
 	PQ_LOCK();
-	pgdebug("f_create(host: %s, port: %s, db: %s).\n",host,port,db);
+#ifdef HAVE_PQSETDBLOGIN
+	conn=PQsetdbLogin(host,port,NULL,NULL,db,user,pass);
+#else
 	conn=PQsetdb(host,port,NULL,NULL,db);
+#endif
 	PQ_UNLOCK();
 	THREADS_DISALLOW();
 	if (!conn)
@@ -372,7 +413,12 @@ static void f_host_info (INT32 args)
 
 	if (PQstatus(THIS->dblink)!=CONNECTION_BAD) {
 		push_text("TCP/IP connection to ");
-		push_text(PQhost(THIS->dblink));
+		pgdebug("adding reason\n");
+		if(PQhost(THIS->dblink))
+			push_text(PQhost(THIS->dblink));
+		else
+			push_text("<unknown>");
+		pgdebug("done\n");
 		f_add(2);
 		return;
 	}
@@ -389,7 +435,7 @@ void pike_module_init (void)
 
 	/* sql-interface compliant functions */
 	add_function ("create",f_create,
-		"function(void|string,void|string,int|void:void)",
+		"function(void|string,void|string,void|string,void|string,int|void:void)",
 		OPT_EXTERNAL_DEPEND);
 	/* That is: create(hostname,database,port)
 	 * It depends on the environment variables:
@@ -423,7 +469,7 @@ void pike_module_init (void)
 
 	postgres_program = end_program();
 	add_program_constant("postgres",postgres_program,0);
-	postgres_program->refs++;
+	add_ref(postgres_program);
 
 	add_string_constant("version",PGSQL_VERSION,0);