473,395 Members | 1,539 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,395 software developers and data experts.

generate random password

I have the following code to generate random passwords for new users of
an application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvw xyz1234567890"

Dim r As Int16, i As Int16
Dim Pswd As String = ""

For i = 1 To len
r = Int((Rnd() * 62) + 1)
Pswd = Pswd & Mid(chars, r, 1)
Next i
Return Pswd

------------

It runs alright, but in the pas couple of days it seems the first time I
run it after starting my asp.net application I always get this same
password: rhjRSwAv

I've actually gotten it three times today. That's not quite random
enough for me. Am I doing something wrong? What can I do to this code to
make the passwords less predictable? Thanks!

Matt
Nov 19 '05 #1
7 2092
JV
Randomizers on a computer are not really very random. Usually one varies a
randomizer by passing it a different seed value each time it is used. You
can use something like the number of timer ticks or maybe the number of
milliseconds reported from DateTime.Now. It's up to you to come up with a
"random enough" scheme.

"MattB" <so********@yahoo.com> wrote
It runs alright, but in the pas couple of days it seems the first time I
run it after starting my asp.net application I always get this same
password: rhjRSwAv

I've actually gotten it three times today. That's not quite random enough
for me. Am I doing something wrong? What can I do to this code to make the
passwords less predictable? Thanks!

Nov 19 '05 #2
Hi Matt

Dont know if this is what you are looking for.
If your need is to create a unique value (temporary password) for a given
user and let him use that only once to log into your site and then ask him
to change his password after that, then you can use Globally Unique
IDentifier GUID in the System namespace.

GUID is a 128-bit integer (16 bytes).

HTH,

Happy Coding

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemguidclasstopic.asp

"MattB" <so********@yahoo.com> wrote in message
news:3b*************@individual.net...
I have the following code to generate random passwords for new users of
an application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvw xyz1234567890"

Dim r As Int16, i As Int16
Dim Pswd As String = ""

For i = 1 To len
r = Int((Rnd() * 62) + 1)
Pswd = Pswd & Mid(chars, r, 1)
Next i
Return Pswd

------------

It runs alright, but in the pas couple of days it seems the first time I
run it after starting my asp.net application I always get this same
password: rhjRSwAv

I've actually gotten it three times today. That's not quite random
enough for me. Am I doing something wrong? What can I do to this code to
make the passwords less predictable? Thanks!

Matt

Nov 19 '05 #3
You should use the Randomize statement. You can pass it a seed value for
additional randomization.

Here's more info:
http://msdn.microsoft.com/library/de...mrandomize.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"MattB" <so********@yahoo.com> wrote in message
news:3b*************@individual.net...
I have the following code to generate random passwords for new users of an
application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvw xyz1234567890"

Dim r As Int16, i As Int16
Dim Pswd As String = ""

For i = 1 To len
r = Int((Rnd() * 62) + 1)
Pswd = Pswd & Mid(chars, r, 1)
Next i
Return Pswd

------------

It runs alright, but in the pas couple of days it seems the first time I
run it after starting my asp.net application I always get this same
password: rhjRSwAv

I've actually gotten it three times today. That's not quite random enough
for me. Am I doing something wrong? What can I do to this code to make the
passwords less predictable? Thanks!

Matt

Nov 19 '05 #4
Steve C. Orr [MVP, MCSD] wrote:
You should use the Randomize statement. You can pass it a seed value for
additional randomization.

Here's more info:
http://msdn.microsoft.com/library/de...mrandomize.asp


Thanks everyone. I think this solution is exactly what I'm after.

Matt
Nov 19 '05 #5
I have seen people take that code, and get the statement to pick two random
words and concatonate them to create a new word. So you have two arrays for
example loaded with words, monkey,day,nuts,tree etc....randomise your choice
and get a decent password generator thats not just random letters and
numbers - it makes usability a lot easier.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"MattB" <so********@yahoo.com> wrote in message
news:3b*************@individual.net...
Steve C. Orr [MVP, MCSD] wrote:
You should use the Randomize statement. You can pass it a seed value for additional randomization.

Here's more info:
http://msdn.microsoft.com/library/de...mrandomize.asp


Thanks everyone. I think this solution is exactly what I'm after.

Matt

Nov 19 '05 #6
I have seen people take that code, and get the statement to pick two random
words and concatonate them to create a new word. So you have two arrays for
example loaded with words, monkey,day,nuts,tree etc....randomise your choice
and get a decent password generator thats not just random letters and
numbers - it makes usability a lot easier.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"MattB" <so********@yahoo.com> wrote in message
news:3b*************@individual.net...
Steve C. Orr [MVP, MCSD] wrote:
You should use the Randomize statement. You can pass it a seed value for additional randomization.

Here's more info:
http://msdn.microsoft.com/library/de...mrandomize.asp


Thanks everyone. I think this solution is exactly what I'm after.

Matt

Nov 19 '05 #7
MattB wrote:
I have the following code to generate random passwords for new users of
an application.

Const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvw xyz1234567890"


Just a word of warning: in some fonts "I", "l" and "1" are very
similar. The same goes for "0", "O" and (maybe) "o". You might
want to leave them out.

--
Hans Kesting
Nov 19 '05 #8

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

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...
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"...
0
sashi
by: sashi | last post by:
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.