#### Tagged as

, 19 Jan 2002
 Rate this:

## Introduction

Do you have a website where users need to login, and when they do you compare the password they enter with a column in a usertable? Some people do logins like this. It's easy to program and it works just fine. But what if someone got hold of the usertable and all the passwords of everyone? You may want to hide or encrypt the passwords in the usertable. Many programming languages have functions to do this. I make ASP-webpages, and I haven't found any quick functions to do this. There are plenty of components to do this, some free of charge even. But what if you cant install components on the webserver

Here is a short and neat way to encrypt your users passwords. You need two strings for it to work. Typically the username and the password.

## Code

```Function encrypt(x1, x2)
s = ""
t = 0
For i = 1 to len(x1)
t = t + asc(mid(x1,i,1))
Next
For i = 1 to len(x2)
y = (t + asc(mid(x2,i,1)) * asc(mid(x2,((i+1) mod len(x2)+1),1))) mod 255
s = s & chr(y)
Next
For i = (len(x2) + 1) to 10
If t>598.8 Then t = 598.8
y = t^3*i mod 255
s = s & chr(y)
Next
encrypt = s
End Function```

If you want to test this function you can create an asp-page and upload it to your website. Here's my codelisting to encrypt.asp

```<%
Function encrypt(x1, x2)
s = ""
t = 0
For i = 1 to len(x1)
t = t + asc(mid(x1,i,1))
Next
For i = 1 to len(x2)
y = (t + asc(mid(x2,i,1)) * asc(mid(x2,((i+1) mod len(x2)+1),1))) mod 255
s = s & chr(y)
Next
For i = (len(x2) + 1) to 10
If t>598.8 Then t = 598.8
y = t^3*i mod 255
s = s & chr(y)
Next
encrypt = s
End Function
%>

<html>
<title>Encrypt</title>

<body>
<% If request.form("name") = "" Then %>
<form action="encrypt.asp" method="post">
<input type="text" name="name"><input type="text" name="pass">
<input type="submit">
</form>
<% Else  %>
<% response.write encrypt(request.form("name"),request.form("pass")) %>
<% End If %>
</body>
</html>```

## Remarks

• The function is not reversible, so there is no way to take the result and reverse it into the password. You will need to recreate the password with a new one (some users seem to forget their passwords and always wants it retreieved)
• This is not a high-level encryption, but its good enough to hide it from lame hackers (hehe).
• The password is always sent from the user inputpage to the page encrypting it. Somewhere in between a hacker can fetch it. Secure zones (SSL) can remedy this.
• Feel free to use the code to whatever you like. But if you alter it make a post in the thread related to this article so we all can share the fun.

A list of licenses authors might use can be found here

## Share

Web Developer
Norway
Tommy live in Tromsø, a city far up north in Norway. He does programming and webdevelopment for a living.

 FirstPrev Next
 Re: its a pretty good article tommy skaue 1-Feb-02 1:18
 Re: its a pretty good article Horatiu CRISTEA 1-Feb-02 3:18
 Re: its a pretty good article tommy skaue 1-Feb-02 3:18
 Tommy's son (off-topic) Oz 22-Jan-02 4:29
 Re: Tommy's son (off-topic) tommy skaue 22-Jan-02 4:32
 Security of the algorithm John Rayner 21-Jan-02 2:24
 Re: Security of the algorithm skaue 21-Jan-02 3:34
 Re: Security of the algorithm Jonas Elfstrom 29-Jan-02 23:41
 I would recommend you to use a well known secure hash function like SHA-1.   I googled for 5 seconds and found: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6545   PS. SHA-1 in Javascript http://pajhome.org.uk/crypt/md5/ DS.
 hashing is already in asp.net Johan Danforth 10-Jan-03 2:10
 Re: hashing is already in asp.net tommy skaue 10-Jan-03 2:14
 A note from the author skaue 21-Jan-02 2:16
 Re: A note from the author James Curran 21-Jan-02 3:42
 Re: A note from the author skaue 21-Jan-02 3:50
 Re: A note from the author James Curran 21-Jan-02 3:49
 Re: A note from the author skaue 21-Jan-02 3:56
 Re: A note from the author Matthias Mann 21-Jan-02 8:32
 Re: UPDATED CODE skaue 21-Jan-02 5:53
 Re: UPDATED CODE Naushad 22-Jan-02 6:32
 Re: UPDATED CODE tommy skaue 23-Jan-02 22:38
 Re: A note from the author Anonymous 19-Apr-02 2:39
 Last Visit: 31-Dec-99 19:00     Last Update: 30-Mar-15 12:47 Refresh 12