Click here to Skip to main content
11,705,610 members (46,997 online)
Click here to Skip to main content

Encrypting Passwords in ASP

, 19 Jan 2002 195K 54
Rate this:
Please Sign up or sign in to vote.
A simple function to encrypt your users passwords
<!-- Add the rest of your HTML here -->

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>
<head>
 <title>Encrypt</title>
</head>

<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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

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

You may also be interested in...

Comments and Discussions

 
GeneralRe: modification of this code Pin
tommy skaue2-Sep-04 21:13
membertommy skaue2-Sep-04 21:13 
GeneralRe: modification of this code Pin
kryzchek18-May-05 7:40
memberkryzchek18-May-05 7:40 
GeneralRe: modification of this code Pin
tommy skaue18-May-05 10:30
membertommy skaue18-May-05 10:30 
GeneralSame function ported to Perl Pin
soffen21-Nov-03 7:55
membersoffen21-Nov-03 7:55 
GeneralReturn value of Encrypt Function Pin
Ven Yetukuri3-Mar-03 8:54
memberVen Yetukuri3-Mar-03 8:54 
GeneralIt wont work this way Pin
StarLite28-Jan-03 9:19
sussStarLite28-Jan-03 9:19 
GeneralRe: It wont work this way Pin
tommy skaue28-Jan-03 21:14
membertommy skaue28-Jan-03 21:14 
GeneralRe: It wont work this way Pin
Anonymous29-Jan-03 3:34
sussAnonymous29-Jan-03 3:34 
GeneralRe: It wont work this way Pin
tommy skaue29-Jan-03 20:59
membertommy skaue29-Jan-03 20:59 
Generalits a pretty good article Pin
Horatiu CRISTEA31-Jan-02 23:30
memberHoratiu CRISTEA31-Jan-02 23:30 
GeneralRe: its a pretty good article Pin
tommy skaue1-Feb-02 0:18
membertommy skaue1-Feb-02 0:18 
GeneralRe: its a pretty good article Pin
Horatiu CRISTEA1-Feb-02 2:18
memberHoratiu CRISTEA1-Feb-02 2:18 
GeneralRe: its a pretty good article Pin
tommy skaue1-Feb-02 2:18
membertommy skaue1-Feb-02 2:18 
GeneralTommy's son (off-topic) Pin
Oz22-Jan-02 3:29
memberOz22-Jan-02 3:29 
GeneralRe: Tommy's son (off-topic) Pin
tommy skaue22-Jan-02 3:32
membertommy skaue22-Jan-02 3:32 
GeneralSecurity of the algorithm Pin
John Rayner21-Jan-02 1:24
memberJohn Rayner21-Jan-02 1:24 
GeneralRe: Security of the algorithm Pin
skaue21-Jan-02 2:34
memberskaue21-Jan-02 2:34 
GeneralRe: Security of the algorithm Pin
Jonas Elfstrom29-Jan-02 22:41
memberJonas Elfstrom29-Jan-02 22:41 
Generalhashing is already in asp.net Pin
Johan Danforth10-Jan-03 1:10
memberJohan Danforth10-Jan-03 1:10 
GeneralRe: hashing is already in asp.net Pin
tommy skaue10-Jan-03 1:14
membertommy skaue10-Jan-03 1:14 
GeneralA note from the author Pin
skaue21-Jan-02 1:16
memberskaue21-Jan-02 1:16 
GeneralRe: A note from the author Pin
James Curran21-Jan-02 2:42
memberJames Curran21-Jan-02 2:42 
GeneralRe: A note from the author Pin
skaue21-Jan-02 2:50
memberskaue21-Jan-02 2:50 
GeneralRe: A note from the author Pin
James Curran21-Jan-02 2:49
memberJames Curran21-Jan-02 2:49 
GeneralRe: A note from the author Pin
skaue21-Jan-02 2:56
memberskaue21-Jan-02 2:56 
GeneralRe: A note from the author Pin
Matthias Mann21-Jan-02 7:32
memberMatthias Mann21-Jan-02 7:32 
GeneralRe: UPDATED CODE Pin
skaue21-Jan-02 4:53
memberskaue21-Jan-02 4:53 
GeneralRe: UPDATED CODE Pin
Naushad22-Jan-02 5:32
memberNaushad22-Jan-02 5:32 
GeneralRe: UPDATED CODE Pin
tommy skaue23-Jan-02 21:38
membertommy skaue23-Jan-02 21:38 
GeneralRe: A note from the author Pin
Anonymous19-Apr-02 1:39
memberAnonymous19-Apr-02 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 20 Jan 2002
Article Copyright 2002 by tommy skaue
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid