473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Generating random password

Hi

How can I generate a random password of 8 characters (digits and letters) in
vb?

Thanks

Regards
Apr 14 '07 #1
3 6727
Dim objRandomNumberGenerator As New System.Random
Dim strPassword As String = ""
Dim intX As Integer

For intX = 1 To 8

'Randomly decide whether or not the next character will be a letter
If objRandomNumberGenerator.Next(0, 2) = 0 Then

'Letter
strPassword &= Chr(objRandomNumberGenerator.Next(97, 123))

Else

'Digit
strPassword &= Chr(objRandomNumberGenerator.Next(48, 58))

End If

Next

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi

How can I generate a random password of 8 characters (digits and letters)
in vb?

Thanks

Regards

Apr 14 '07 #2
Hi John, almost the same :)

Public Function GeneratePassword(ByVal len As Integer) As String
Dim str As String =
"1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASD FGHJKLZXCVBNM"
Dim N As Integer = str.Length
Dim rnd As New Random((Now.Hour * 3600 + Now.Minute * 60 +
Now.Second) * 1000 + Now.Millisecond)
Dim sb As New StringBuilder

For l As Integer = 1 To len
sb.Append(str.Substring(rnd.Next(0, N), 1))
Next
Return sb.ToString
End Function

generates 'random' passwords every 1 millisecond. Using inside class
scope make random number generator Shared to avoid this
limitation. :))
Kind regards
Serge
http://www.sergejusz.com

Apr 14 '07 #3
John wrote:
Hi

How can I generate a random password of 8 characters (digits and letters) in
vb?

Thanks

Regards
Make a string that contains the characters that you want to use. Here
you can remove the characters that easily can be misinterpreted, like 1,
l, I, o , O, 0. Pick characters by random from the string.

Example:

Dim chars as String = "2345ABCD"
Dim password as String = ""
Dim r as New Random()
Dim i as Integer
For i = 1 to 8
password += chars.Substring(r.Next(chars.Length), 1)
Next

--
Göran Andersson
_____
http://www.guffa.com
Apr 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Fox | last post by:
The recent thread in generating PINs reminded me: Suppose I want to give someone a random password or ID then this is what I do: (1) Generate a hash, eg. MD5 form something, possibly a random...
2
by: Joe | last post by:
Hi, I am building web in ASP.NET using VB.NET to code the pages. I want to generate random passwords for users. I know that password hashing is built right into the .NET Framework. I was...
3
by: John | last post by:
Hi I need to generate a string of six random characters to act as the first password. Is there an example of how to do this somewhere? Thanks Regards
5
by: k.i.n.g. | last post by:
Hi, I have a csv file which in taken as the input file for adding users in my linux mail server with the format userid,fullname,passwword,dateofbith Now I have to write a script to generate...
2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
2
by: randomcz | last post by:
hi, i need help with generating random numbers; The task is to generate hundreds of random vectors, like 1,3,5,6,7 2,4,5,4,8 ... I used the current time as the random seed, but it turns...
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
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"...
1
by: Krimp | last post by:
I pulled this code from Vbasic.net or generating random passwords. I want to know how I can set up so that each time the page is refreshed a new password is generated without having to fill in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.