Jump to content

Recommended Posts

Posted (edited)

Hey Guys,

This is a two part post. The first part being that I am attempting (emphasis on attempt) to give back to this amazing community who has been more than helpful to me.

The second part being my coming of age in this autoit/pseudo-programming environment, and how I would like to evolve my code into a more modular fashion.

The code I will post was the product of my hard work today. As I am a noob, it took me almost all day at work (while ignoring most of my other tasks) to get the code to work.

here is a little background. The code is a Random (primitive) Password Generator that meets the following four requirements (as required by my workplace):

- must have at least one lowercase

- must have at least one uppercase

- must have at least one number

- must have at least one special character

- must be at least 8 characters long.

That being said, I open my code up for your worldly critique (if anyone even cares). My request to you is that you suggest a better way for me to code, so that I am call this specific function from another AU3 script that will be a GUI.

The master plan is to convert all my former (and hopefully future) scripts in a way that I can call most (not all) of them through a GUI.

Ok here it is.

#include <Array.au3>
opt("trayicondebug", 1)
; Script Start - Add your code below here
;~ *******************************************
;~ Variables
;~ *******************************************

$x = 26
$pwdlength = InputBox("Password Length","How long do you want your password to be?"&@lf&"Default is 8 max is 32",8)
$z = 11
dim $Lowercase[$x]
dim $Uppercase[$x]
Dim $Password[$pwdlength]
Dim $Numeric[10]
Dim $Special[$z]
DIm $pos[$pwdlength]
Dim $req[4]
$req[0] = "Lowercase"
$req[1] = "Uppercase"
$req[2] = "Numeric"
$req[3] = "Special"


;~ *******************************************
;~ Main Process
;~ *******************************************
for $j = 0 to ($x-1)                    ;       Set Arrayitem = ASCII Char + Array position;;   
    $Lowercase[$j] = chr(97 + $j)
    $uppercase[$j] = chr(65 +$j)
Next

For $j = 0 to 9                         ;       Set Arrayitem = ASCII Char + Array position;; 
    $Numeric[$j] = chr(48 + $j)
Next    

For $j = 0 to 10                        ;       Set Arrayitem = ASCII Char + Array position;; 
    $special[$j] = chr(33 +$j)
Next

$Uppercase_size = Ubound($uppercase) 
$Lowercase_size = Ubound($Lowercase)
$numeric_size = Ubound($numeric)
$Special_Size = UBound($Special)

_randompassword()


$rndm_pass =_ArrayToString($Password," ");      convert all elements of the $password Array into a String called $RNDPASS
$rndm_pass = StringReplace($rndm_pass," ","");      Eleminate the spaces from the $rndmpass String

MsgBox(0,"password",$rndm_pass)

exit 
;~ *******************************************
;~ FUNCTIONS
;~ *************************** ****************
Func _randompassword()
For $j = 0 to 3
    $pos[$j] = random(0, $pwdlength -1,1)
    if  isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0 
    endif
        $req_crit=$req[$j]; ex: $reg[$j] = lowercase
        $req_crit_array = eval($req_crit);ex; $test = $lowercase
        $password[$pos[$j]] = $req_crit_array[random(0,eval($req_crit&"_Size")-1,1)]
next 

For $j = 4 to $pwdlength-1
    $pos[$j] = random(0, $pwdlength -1,1)
    if  isstring($Password[$pos[$j]])= 1 Then
        do
        $pos[$j] = random(0, $pwdlength -1,1)
        until isstring($Password[$pos[$j]])= 0 
    endif
    $random_crit = $req[random(0,3,1)]
    $random_crit_array = eval($random_crit) 
    $password[$pos[$j]] = $random_crit_array[random(0,eval($random_crit&"_Size")-1,1)]
next 

EndFunc

PS: please be gently, im not very good with arrays.

Random_Password_Generator_1.0.au3

Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Posted

I havent tried the code, but I may find a need for it as my job right now may require something similiar.

I havent ever messed with UBound() much. I have just ignored it mostly. I have a decent grasp of array's themselves, just not the whole UBound bit. Although I seem to have a basic understanding of it. Just never seen the need to use it, and until I use something I dont feel I can have an accurate opinion of it.

Might try and post this in Scripts and Scraps, unless there is a particular part you are having trouble with. Most people dont check the Support forum for scripts.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Posted

I havent tried the code, but I may find a need for it as my job right now may require something similiar.

I havent ever messed with UBound() much. I have just ignored it mostly. I have a decent grasp of array's themselves, just not the whole UBound bit. Although I seem to have a basic understanding of it. Just never seen the need to use it, and until I use something I dont feel I can have an accurate opinion of it.

Might try and post this in Scripts and Scraps, unless there is a particular part you are having trouble with. Most people dont check the Support forum for scripts.

JS

Thanks.

How do I move this post to the scripts and scraps? do I just copy and repost my initial thread?

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Posted

Thanks.

How do I move this post to the scripts and scraps? do I just copy and repost my initial thread?

You cannot move the post. It would have to be one of the forum moderators. I would give it a day or two to move, and then just repost if it doesnt move in that time frame.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Posted

Anyone?

here's an alternate way, a little less code...

Func RandomPass($length=8)
    $number = Random(1,$length,1)
Do
    $thecap = Random(1,$length,1)
Until $number <> $thecap
Do
    $thelow = Random(1,$length,1)
Until $thelow <> $thecap And $thelow <> $number
Do
    $special = Random(1,$length,1)
Until $thelow <> $special And $special <> $number And $special <> $thecap
$all = ".!-#*/&0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

$pass = ""
For $x = 1 to $length
    Select
    Case $x = $number
        $pass = $pass & chr(Random(48,57,1))
    Case $x = $thecap
        $pass = $pass & Chr(Random(65,90,1))
    Case $x = $thelow
        $pass = $pass & Chr(Random(97,122,1))
    Case $x = $special
        $pass = $pass & Chr(Random(33,46,1))
    Case Else
        $pass = $pass & StringMid($all,Random(1,StringLen($all),1))
    EndSelect
Next
MsgBox(0,"Password","Your generated password is: " & @LF & $pass)
EndFunc

and it's a self contained function, so you can call it from any script you include it in...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...