DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples > Classic ASP

Discuss "Random Key Generator" in the Classic ASP forum.

Classic ASP - Post your Classic ASP code samples here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old March 19th, 2008, 01:07 PM
BLaaaaaaaaaarche's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 43
Thanks: 10
Thanked 6 Times in 4 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

Default Random Key Generator

Have you ever wanted to create a random key to store in a session or pass along through the querystring? Well, here is a simple solution to generate a random key using letters and numbers that can be any length you wish:

Code:
Function generateKey(keyLength)
	' Initialize variables
	sDefaultChars = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
	iKeyLength = keyLength
	iDefaultCharactersLength = Len(sDefaultChars)

	' Initialize the random number generator
	Randomize

	'Loop for the number of characters password is to have
	For iCounter = 1 To iKeyLength
		iPickedChar = Int((iDefaultCharactersLength * Rnd) + 1)
		sMyKey = sMyKey & Mid(sDefaultChars, iPickedChar, 1)
	Next
	generateKey = sMyKey
End Function
To generate the key (with length of 30 characters), simply use the following:

Code:
strKey = generateKey(30)
You can also modify the sDefaultChars string to allow other characters as well.

Happy programming.

Comments on this post
jmurrayhead agrees:
Reply With Quote
Sponsored Links
Reply

  DeveloperBarn Forums > Programming & Scripting > Code Samples > Classic ASP

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 08:53 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46