diff -urNB emech-2/src/Makefile.in emech-2-sha/src/Makefile.in
--- emech-2/src/Makefile.in	Wed Feb 14 19:49:30 2001
+++ emech-2-sha/src/Makefile.in	Tue Mar 20 05:28:16 2001
@@ -36,10 +36,10 @@
 INCS =		config.h mcmd.h defines.h global.h h.h structs.h
 
 OBJS =		cfgfile.o channel.o com-ons.o combot.o commands.o dcc.o debug.o function.o \
-		link.o main.o parse.o socket.o userlist.o vars.o xmech.o
+		link.o main.o parse.o sha.o socket.o userlist.o vars.o xmech.o
 
 CFILES =	cfgfile.c channel.c com-ons.c combot.c commands.c dcc.c debug.c function.c \
-		link.c main.c parse.c socket.c userlist.c vars.c xmech.c
+		link.c main.c parse.c sha.c socket.c userlist.c vars.c xmech.c
 
 all:		$(INSTALLNAME)
 
@@ -98,6 +98,9 @@
 
 parse.o:	parse.c $(INCS)
 		$(CC) $(CFLAGS) parse.c $(CPROF)
+
+sha.o:	sha.c $(INCS)
+		$(CC) $(CFLAGS) sha.c $(CPROF)
 
 socket.o:	socket.c $(INCS)
 		$(CC) $(CFLAGS) socket.c $(CPROF)
diff -urNB emech-2/src/config.h.in emech-2-sha/src/config.h.in
--- emech-2/src/config.h.in	Tue Mar 20 04:04:30 2001
+++ emech-2-sha/src/config.h.in	Tue Mar 20 05:28:16 2001
@@ -165,7 +165,7 @@
 #define MAXLOGINLEN			11
 #define LOGINBUF			MAXLOGINLEN+1
 
-#define PASSLEN				20
+#define PASSLEN				42
 #define PASSBUF				PASSLEN+1
 
 #define MINPASSCHARS			4
diff -urNB emech-2/src/function.c emech-2-sha/src/function.c
--- emech-2/src/function.c	Tue Feb 27 17:09:12 2001
+++ emech-2-sha/src/function.c	Tue Mar 20 05:28:16 2001
@@ -950,7 +950,8 @@
 }
 
 /*
- *  energymech password encryption
+ *  Legacy energymech password encryption.
+ *  Will be removed in future versions.
  */
 
 char	pctab[] =
@@ -976,7 +977,7 @@
 	a1 >>= 1;			\
 }
 
-char *cipher(char *arg)
+char *old_cipher(char *arg)
 {
 	static	char res[40];
 	Ulong	B1a,B2a,B3a,B4a;
@@ -1024,6 +1025,33 @@
 	return(res);
 }
 
+/* 
+ * New SHA password hash
+ */
+
+char *cipher(char *arg)
+{
+	static	char res[PASSBUF];
+	char	data[64];
+	int	hashval[5];
+
+	if (!arg || !*arg)
+		return(NULL);
+
+	memset(data,0,sizeof(data));
+	strcpy(data,arg);
+
+	sha_init(hashval);
+	sha_hash((int *)data,hashval);
+
+	sprintf(res, "%08X%08X%08X%08X%08X",
+		hashval[0],	hashval[4],
+		hashval[1],	hashval[3],
+		hashval[2]);
+        
+	return(res);
+}
+
+
 void makepass(char *encoded, char *plain)
 {
 	strcpy(encoded,cipher(plain));
@@ -1031,7 +1059,14 @@
 
 int passmatch(char *plain, char *encoded)
 {
-	return(!Strcasecmp(cipher(plain),encoded));
+	if (strlen(encoded) > 10)
+	{
+		return(!Strcasecmp(cipher(plain),encoded));
+	}
+	else
+	{
+		return(!Strcasecmp(old_cipher(plain),encoded));
+	}
 }
 
 int check_for_number(char *from, char *string)
diff -urNB emech-2/src/h.h emech-2-sha/src/h.h
--- emech-2/src/h.h	Tue Feb 27 11:29:28 2001
+++ emech-2-sha/src/h.h	Tue Mar 20 05:28:16 2001
@@ -155,6 +155,7 @@
 char *idle2str(time_t, int);
 char *mstrcpy(char **, char *);
 char *nick2uh(char *, char *, int);
+char *old_cipher(char *);
 char *randstring(char *);
 char *right(char *, int);
 char *sockread(int, char *, char *);
@@ -217,6 +218,8 @@
 int send_chat(char *, char *);
 int send_to_socket(int, char *, ...);
 int set_enftopic(char *, char *);
+int sha_hash(int *, int *);
+int sha_init(int *);
 int shit_action(char *, aChan *);
 int show_names_on_channel(char *, char *);
 int SockConnect(char *, int, int);
diff -urNB emech-2/src/main.c emech-2-sha/src/main.c
--- emech-2/src/main.c	Mon Mar  5 18:31:49 2001
+++ emech-2-sha/src/main.c	Tue Mar 20 05:28:16 2001
@@ -32,6 +32,7 @@
 #include "function.c"
 #include "link.c"
 #include "parse.c"
+#include "sha.c"
 #include "socket.c"
 #include "userlist.c"
 #include "vars.c"
diff -urNB emech-2/src/sha.c emech-2-sha/src/sha.c
--- emech-2/src/sha.c	Wed Dec 31 19:00:00 1969
+++ emech-2-sha/src/sha.c	Tue Mar 20 07:02:46 2001
@@ -0,0 +1,131 @@
+/*
+
+    Starglider Class EnergyMech, IRC bot software
+    Parts Copyright (c) 1997-2000  proton
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+    Implements the Secure Hash Algorithm (SHA1)
+       Copyright (C) 1999 Scott G. Miller
+       Released under the terms of the GNU General Public License v2.
+    Credits:
+       Robert Klep <robert@ilse.nl>  -- Expansion function fix 
+
+*/
+
+#include <endian.h>
+
+#if !(defined(__alpha)||defined(__i386__)||defined(__vax__))
+#define BIG_ENDIAN
+#endif
+
+#define switch_endianness(x) (x<<24 & 0xff000000) | \
+                             (x<<8  & 0x00ff0000) | \
+                             (x>>8  & 0x0000ff00) | \
+                             (x>>24 & 0x000000ff)
+
+#define Ai 0x67452301 
+#define Bi 0xefcdab89
+#define Ci 0x98badcfe
+#define Di 0x10325476
+#define Ei 0xc3d2e1f0
+#define K1 0x5a827999
+#define K2 0x6ed9eba1
+#define K3 0x8f1bbcdc 
+#define K4 0xca62c1d6
+#define f1(B,C,D) ((B & C) | ((~B) & D))
+#define f2(B,C,D) (B ^ C ^ D)
+#define f3(B,C,D) ((B & C) | (B & D) | (C & D))
+#define rol1(x) ((x<<1) | ((x>>31) & 1))
+#define rol5(A) ((A<<5) | ((A>>27) & 0x1f))
+#define rol30(B) ((B<<30) | ((B>>2) & 0x3fffffff))
+
+int 
+sha_hash(int *data, int *hash)  
+{
+  int W[80];
+  unsigned int A=hash[0], B=hash[1], C=hash[2], D=hash[3], E=hash[4];
+  unsigned int t, x, TEMP;
+
+  for (t=0; t<16; t++) 
+    {
+#ifdef BIG_ENDIAN
+      W[t]=switch_endianness(data[t]);
+#else 
+      W[t]=data[t];
+#endif
+    }
+
+
+  for (t=16; t<80; t++) 
+    {
+      x=W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16];
+      W[t]=rol1(x);
+    }
+
+  for (t=0; t<20; t++) 
+    {
+      TEMP=rol5(A) + f1(B,C,D) + E + W[t] + K1;
+      E=D;
+      D=C;
+      C=rol30(B);
+      B=A;
+      A=TEMP;
+    }
+  for (; t<40; t++) 
+    {
+      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K2;
+      E=D;
+      D=C;
+      C=rol30(B);
+      B=A;
+      A=TEMP;
+    }
+  for (; t<60; t++) 
+    {
+      TEMP=rol5(A) + f3(B,C,D) + E + W[t] + K3;
+      E=D;
+      D=C;
+      C=rol30(B);
+      B=A;
+      A=TEMP;
+    }
+  for (; t<80; t++) 
+    {
+      TEMP=rol5(A) + f2(B,C,D) + E + W[t] + K4;
+      E=D;
+      D=C;
+      C=rol30(B);
+      B=A;
+      A=TEMP;
+    }
+  hash[0]+=A; 
+  hash[1]+=B;
+  hash[2]+=C;
+  hash[3]+=D;
+  hash[4]+=E;
+  return(0);
+}
+
+int 
+sha_init(int *hash) 
+{
+  hash[0]=Ai;
+  hash[1]=Bi;
+  hash[2]=Ci;
+  hash[3]=Di;
+  hash[4]=Ei;
+  return(0);
+}

