473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,322 developers and data experts.

Generate Random Password

sashi
1,754 Expert 1GB
Generate Random Password

In the course of programming you may have cause to generate a password. The following function will generate a password of randomly selected characters up to a maximum of 10 characters (this is easy to increase). The number of characters required is passed as a parameter.

Using this type of procedure as opposed to chosing your own passwords makes for better security.

Expand|Select|Wrap|Line Numbers
  1. 'Form code - frmPasswordGenerate
  2.  
  3. Private Declare Function GetTickCount Lib "kernel32" () As Long
  4.  
  5. Public Function PassGen(nLen As Integer)
  6. Dim range As Collection
  7. Dim ivalue, icount, iLen As Long
  8. Dim pass As String
  9.  
  10.     Set range = New Collection
  11.     range.Add ("0")
  12.     range.Add ("1")
  13.     range.Add ("2")
  14.     range.Add ("3")
  15.     range.Add ("4")
  16.     range.Add ("5")
  17.     range.Add ("6")
  18.     range.Add ("7")
  19.     range.Add ("8")
  20.     range.Add ("9")
  21.  
  22.     icount = 0
  23.     ivalue = 0
  24.     iLen = range.Count
  25.  
  26.     Do Until icount = nLen
  27.       Randomize
  28.       ivalue = CByte(Mid(CStr(Rnd(GetTickCount)), 3, 2))
  29.        If ivalue > 0 And ivalue <= iLen Then
  30.           icount = icount + 1
  31.           pass = pass & range(ivalue)
  32.        End If
  33.     Loop
  34.  
  35. PassGen = pass
  36. End Function
  37.  
  38. Private Sub cmdGeneratePassword_Click()
  39.     MsgBox PassGen(8)
  40. End Sub
  41.  
Dec 4 '06 #1
0 8606

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
5
by: Alistair | last post by:
Hello folks... this is my first post in here. I'm new to ASP having done all my previous work in Flash and bog standard HTML. Only been learning for a couple of weeks. anyway...I have been...
15
by: John Cassidy | last post by:
This has been driving me crazy. I've done basic C in school, but my education is mainly based on object oriented design theory where Java is our tool. For some reason, while helping a friend with a...
2
by: Joe | last post by:
Hi, I want to generate a random password every time a new user account is created. I want to include small and capital letters and 0 to 9 digits. Can someone give me some idea as how should I do...
7
by: MattB | last post by:
I have the following code to generate random passwords for new users of an application. Const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvwxyz1234567890" Dim r As Int16, i As...
5
by: Raghuram | last post by:
I want to generate some set of chars which are more than 4 chars randomly. . .. how can i do that
3
by: Army1987 | last post by:
Is there anything wrong with this program? It seems to behave strangely if I give stdin EOF when asked for the character set... /* BEGIN pwdgen.c */ #include <stdio.h> #include "random.h"...
5
by: ashurack | last post by:
I found a stored procedure online a while back and want to inplement it. The only problem is that it doesn't check to see if the number generated is currently in use in the DB. I know it's really...
0
by: Jonathan Boivin | last post by:
If I could give an advice on your method, in fact, what I would do.. is : Generate a password with your lower security set of characters. Then upper case randomizally some letters and finally...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.