Solved

ASP/VB script page - SP help

Posted on 2014-01-02
4
490 Views
Last Modified: 2014-01-02
I am using ASP/VB script and MS SQL 2008

There is a SP in my page that inserts data in my DB.

---

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

----

The above will insert the word "demo" into a database field, when it is inserted it is also enctrypted.  That is what the "Encrypt" part is for, so far so good.

I have to replace the word "demo" for a random password.  I already have the script below to generate a random password. What I need help with is to save the random password in a variable and then use it to insert it instead of the word 'demo' using the code above.

This is my script:

<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>
0
Comment
Question by:amucinobluedot
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39752732
to put the newly created 10 char password into a variable, just do:

SPInsertPassword__Password = EncrytPswd( GeneratePassword( 10 ) )

do you also need help saving it?
0
 

Author Comment

by:amucinobluedot
ID: 39752750
let me try the above first.
0
 

Author Comment

by:amucinobluedot
ID: 39752759
Great, thanks !
0
 

Author Closing Comment

by:amucinobluedot
ID: 39752760
:)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now