diff --git a/lib/modules/Sql.pmod/postgres.pike b/lib/modules/Sql.pmod/postgres.pike
index f6407d0c87bf048c808cc22ecb2f9f7e293da314..3f240538f165005f0c75c2085499856fcbdceec6 100644
--- a/lib/modules/Sql.pmod/postgres.pike
+++ b/lib/modules/Sql.pmod/postgres.pike
@@ -2,7 +2,7 @@
  * This is part of the Postgres module for Pike.
  * (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
  *
- * $Id: postgres.pike,v 1.3 1998/07/15 19:04:18 grubba Exp $
+ * $Id: postgres.pike,v 1.4 1998/08/25 13:11:21 grubba Exp $
  *
  */
 
@@ -31,7 +31,7 @@ void create(void|string host, void|string database, void|string user,
 		if (sscanf(host,"%s:%d",real_host,port)!=2)
 			ERROR("Error in parsing the hostname argument.\n");
 	
-	mo::create(real_host||"",real_db||"",port);
+	mo::create(real_host||"",real_db||"",user||"",pass||"",port);
 }
 
 static void poll (int delay)
diff --git a/src/modules/Postgres/configure.in b/src/modules/Postgres/configure.in
index 404685d52a7285439d2b90dc1d72b6d0b0aa155b..08c2a8c2375a05614b621402afee470f08e71709 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 19:02:17 grubba Exp $
+dnl $Id: configure.in,v 1.7 1998/08/25 13:11:50 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/pgres_config.h.in b/src/modules/Postgres/pgres_config.h.in
index b3564808a53c355fb445823490a5adcb88c86eba..9a1ce0ab5888fb458265a01c51aee4ed3f97d618 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:11:51 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/postgres.c b/src/modules/Postgres/postgres.c
index 8ab788ce54943caa4a5a60fd87cc21017c17d116..2d209f3f4d71d284e36a064342143ad6caac03c5 100644
--- a/src/modules/Postgres/postgres.c
+++ b/src/modules/Postgres/postgres.c
@@ -62,7 +62,7 @@ static void pgdebug (char * a, ...) {}
 
 struct program * postgres_program;
 
-RCSID("$Id: postgres.c,v 1.8 1998/07/15 18:52:28 grubba Exp $");
+RCSID("$Id: postgres.c,v 1.9 1998/08/25 13:11:52 grubba Exp $");
 
 #define THIS ((struct pgres_object_data *) fp->current_storage)
 
@@ -106,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;
@@ -123,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;
@@ -143,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)
@@ -371,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;
 	}
@@ -388,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: