Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

script for random password not working

Posted on 2014-02-12
7
441 Views
Last Modified: 2014-02-12
I have the following script to generate a random password, but it is assingning the SAME password every time, not randomizing it.

What is wrong with it ?

---

<script language="vbscript" runat="server">

Sub StrRandomize(strSeed)
        Dim i, nSeed
        nSeed = CLng(0)
        For i = 1 To Len(strSeed)
                nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
        Next
        'Randomiser
        Randomize nSeed
End Sub
'--GeneratePassword(nLength)
'--Generates friendly passwords for remembering and pronounciation
Function GeneratePassword(nLength)
        Dim i, bMadeConsonant, c, nRnd
		'You may adjust the below constants to include local,
		'eg. scandinavian characters. This way your passwords
		'will not be limited to latin characters.
        Const strDoubleConsonants = "bdfglmnpst"
        Const strConsonants = "bcdfghklmnpqrstv"
        Const strVocal = "aeiou"
        GeneratePassword = ""
        bMadeConsonant = False
        For i = 0 To nLength
                'Get a random number number between 0 and 1
                nRnd = Rnd
                'Simple or double consonant, or a new vocal?
                'Does not start with a double consonant
				'15% or less chance for the next letter being a double consonant
                If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
                        'double consonant
                        c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
						'response.write int(Len(strDoubleConsonants) * Rnd + 1)
						'response.write "<br>"
                        c = c & c
						i = i + 1
                        bMadeConsonant = True
                Else
						'80% or less chance for the next letter being a consonant,
						'depending on wether the last letter was a consonant or not.
                        If (bMadeConsonant <> True) And (nRnd < 0.95) Then
                                'Simple consonant
                                c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
                                bMadeConsonant = True
						'5% or more chance for the next letter being a vocal. 100% if last
						'letter was a consonant - theoreticaly speaking...
                        Else
                                'If last one was a consonant, make vocal
                                c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
                                bMadeConsonant = False
                        End If
                End If
                'Add letter
                GeneratePassword = GeneratePassword & c
        Next
        'Is the password long enough, or perhaps too long?
        If Len(GeneratePassword) > nLength Then
                GeneratePassword = Left(GeneratePassword, nLength)
        End If
End Function

StrRandomize CStr(Now) & CStr(Rnd)

</script>

Open in new window

----

Then the value I assign to it is:  

This is part of the code that assigns the value:

Dim SPInsertPassword__Password
SPInsertPassword__Password = "0"
if(EncrytPswd( GeneratePassword( 10 ) ) <> "") then SPInsertPassword__Password = EncrytPswd( GeneratePassword( 10 ) )

Open in new window

0
Comment
Question by:amucinobluedot
  • 3
  • 2
7 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 250 total points
ID: 39854497
Put all of your randomizing in a function. See how this test works out....

function testRand()
   randomize
   testRand=Rnd
end function
for x = 1 to 10
   response.write testRand&"<br>"

next
        

Open in new window

0
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 250 total points
ID: 39854543
In your example place Randomize prior to line 62 "StrRandomize CStr(Now) & CStr(Rnd)"

so you code will look like:

<script language="vbscript" runat="server">

Sub StrRandomize(strSeed)
        Dim i, nSeed
        nSeed = CLng(0)
        For i = 1 To Len(strSeed)
                nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
        Next
        'Randomiser
        Randomize nSeed
End Sub
'--GeneratePassword(nLength)
'--Generates friendly passwords for remembering and pronounciation
Function GeneratePassword(nLength)
        Dim i, bMadeConsonant, c, nRnd
		'You may adjust the below constants to include local,
		'eg. scandinavian characters. This way your passwords
		'will not be limited to latin characters.
        Const strDoubleConsonants = "bdfglmnpst"
        Const strConsonants = "bcdfghklmnpqrstv"
        Const strVocal = "aeiou"
        GeneratePassword = ""
        bMadeConsonant = False
        For i = 0 To nLength
                'Get a random number number between 0 and 1
                nRnd = Rnd
                'Simple or double consonant, or a new vocal?
                'Does not start with a double consonant
				'15% or less chance for the next letter being a double consonant
                If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
                        'double consonant
                        c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
						'response.write int(Len(strDoubleConsonants) * Rnd + 1)
						'response.write "<br>"
                        c = c & c
						i = i + 1
                        bMadeConsonant = True
                Else
						'80% or less chance for the next letter being a consonant,
						'depending on wether the last letter was a consonant or not.
                        If (bMadeConsonant <> True) And (nRnd < 0.95) Then
                                'Simple consonant
                                c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
                                bMadeConsonant = True
						'5% or more chance for the next letter being a vocal. 100% if last
						'letter was a consonant - theoreticaly speaking...
                        Else
                                'If last one was a consonant, make vocal
                                c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
                                bMadeConsonant = False
                        End If
                End If
                'Add letter
                GeneratePassword = GeneratePassword & c
        Next
        'Is the password long enough, or perhaps too long?
        If Len(GeneratePassword) > nLength Then
                GeneratePassword = Left(GeneratePassword, nLength)
        End If
End Function

Randomize
StrRandomize CStr(Now) & CStr(Rnd)

</script>
                                  

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 39854725
I tried the above and still always gives me back the SAME password
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:amucinobluedot
ID: 39854739
It generates the password but it doesn't ranfomize it, its always the same.
0
 

Author Comment

by:amucinobluedot
ID: 39854788
I am trying this now:

----

<%
Dim firstNumber, firstLower, firstUpper, firstOther, latterNumber, _
latterLower, latterUpper, latterOther, passwordLength, extraChars 

firstNumber = "true"
firstLower =  "true"
firstUpper =  "true"
firstOther =  "false"
latterNumber = "true"
latterLower = "true"
latterUpper = "true"
latterOther = "false"
passwordLength = 10
extraChars = "@$!"

Function getRandomNum(lbound, ubound) 
For j = 1 To (250 - ubound)
	Randomize 
	getRandomNum = Int(((ubound - lbound) * Rnd) + 1)
Next 
End Function

Function getRandomChar(number, lower, upper, other, extra) 
numberChars = "0123456789"
lowerChars = "abcdefghijklmnopqrstuvwxyz"
upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:"""'\,<.>/? "
charSet = extra
	if (number = "true") Then charSet = charSet + numberChars
	if (lower = "true") Then charSet = charSet + lowerChars
	if (upper = "true") Then charSet = charSet + upperChars
	if (other = "true") Then charSet = charSet + otherChars
jmi = Len(charSet) 
getRandomChar = Mid(charSet, getRandomNum(1, jmi), 1)
End Function

Function getPassword(length, extraChars, firstNumber, firstLower, _
firstUpper, firstOther, latterNumber, latterLower, latterUpper, latterOther)
rc = ""
	If (length > 0) Then
		rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars)
	End If

	For idx = 1 To length - 1
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars)
	Next
getPassword = rc
End Function

strUltraPass = getPassword(passwordLength, extraChars, _
firstNumber, firstLower, firstUpper, firstOther, _
latterNumber, latterLower, latterUpper, latterOther)
%>
<%Session("svPassword") = strUltraPass%>

Open in new window

----

But apparently no value is being entered into the database.



Dim SPInsertPassword__Password
SPInsertPassword__Password = "0"
if(EncrytPswd( Session("svPassword") ) <> "") then SPInsertPassword__Password = EncrytPswd( Session("svPassword") )

Open in new window



What could the issue be ?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39855119
Just another idea to that may make this a little easier.  You can use the ascii character set http://ascii-code.com/.  In asp you can access this by chr(x) where x is the character number. This little sample uses just the lower case set.  But if you changed the min value to 22 you would get special characters and  upper case.  

<%

function makeWord()
Dim max,min
 max=122
 min=97
 Randomize
 number = (Int((max-min+1)*Rnd+min))
 makeWord =chr(number)
end function
newPass=""
for x =1 to 10
	newPass=newPass&makeWord
next
response.write newPass
%>

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automatically create a conditional formatting rule in all users' outlook in organization 4 133
ASP server side get value 15 35
If condition on Html with Asp 11 28
IIS components 2 15
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question