Venix Posted February 26, 2013 Posted February 26, 2013 (edited) Hello guys . So I have been trying to make a function that will create an array of random passwords and also allows the user to select how much passwords they want to be generated and the length of each of those passwords. It was coming along quite smoothly for the most part however I have hit a wall in my progress and I am a bit stuck. When the final array is displayed because of the way in which I have coded it half of the arrays are empty and the rest are the generated passwords. I believe this is because I declare my array with x amount of values but don't add values until later on. My original logic was that I was going to declare the array and assumed it would be completely empty until I defined the values at a later stage but this is not the case and if I try to define the values and they are not listed directly under the array I will of course get a syntax error. I really am not sure how to proceed hope someone can help. Sorry if you don't understand my explanation I am having trouble finding the right words to describe the issue. Please note I will likely never use this function in the future however decided to make it out of practice so if there is anyone with a more urgent issue then just ignore this post for now . #include <Array.au3> PassGen(10,10) Func PassGen($i_PWlength, $i_GenCount) ;Variable contains most keys with the exception of some special characters. $Keys = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," $Keys &= "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," $Keys &= "0,1,2,3,4,5,6,7,8,9," $Keys &= "`,!,£,$,%,^,&,*,(,),-,_,=,+,{,[,},],;,@,~,#,?,<,>,/,\" $KeyValue = StringSplit($Keys, ",", 0) $CurrentPW = "" Local $PWLog[$i_GenCount] For $i_1 = 0 to $i_GenCount Step 1 For $i_2 = 0 to $i_PWlength Step 1 $CurrentPW = $CurrentPW & $KeyValue[Random(0, $KeyValue[0])] Next _ArrayAdd($PWLog, $CurrentPW) $CurrentPW = "" Next _ArrayDisplay($PWLog, "Password Log") EndFunc ;==>PassGen Forum removed my tabbing >_< Edited February 26, 2013 by Venix
kylomas Posted February 26, 2013 Posted February 26, 2013 Venix, "arrayadd" add an enty to the end of an array. See corrected code. #include <Array.au3> PassGen(10, 10) Func PassGen($i_PWlength, $i_GenCount) ;Variable contains most keys with the exception of some special characters. $Keys = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," $Keys &= "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," $Keys &= "0,1,2,3,4,5,6,7,8,9," $Keys &= "`,!,£,$,%,^,&,*,(,),-,_,=,+,{,[,},],;,@,~,#,?,<,>,/,\" $KeyValue = StringSplit($Keys, ",", 0) $CurrentPW = "" Local $PWLog[1] ; look up arrayadd in help file For $i_1 = 0 To $i_GenCount Step 1 For $i_2 = 0 To $i_PWlength Step 1 $CurrentPW = $CurrentPW & $KeyValue[Random(0, $KeyValue[0])] Next _ArrayAdd($PWLog, $CurrentPW) $CurrentPW = "" Next _arraydelete($PWLog,0) _ArrayDisplay($PWLog, "Password Log") EndFunc ;==>PassGen kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Venix Posted February 26, 2013 Author Posted February 26, 2013 Thank you, I guess I was not using the function correctly, I assumed that I would get an error for using ArrayAdd if my array could only hold 1 value.
JohnOne Posted February 26, 2013 Posted February 26, 2013 (edited) #include <Array.au3> PassGen(10, 10) Func PassGen($i_PWlength, $i_GenCount) ;Variable contains most keys with the exception of some special characters. $Keys = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z," $Keys &= "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," $Keys &= "0,1,2,3,4,5,6,7,8,9," $Keys &= "`,!,£,$,%,^,&,*,(,),-,_,=,+,{,[,},],;,@,~,#,?,<,>,/,\" $KeyValue = StringSplit($Keys, ",", 0) $CurrentPW = "" Local $PWLog[$i_GenCount] For $i_1 = 0 To $i_GenCount - 1 Step 1 For $i_2 = 0 To $i_PWlength Step 1 $CurrentPW = $CurrentPW & $KeyValue[Random(0, $i_GenCount - 1, 1)] Next $PWLog[$i_1] = $CurrentPW $CurrentPW = "" Next _ArrayDisplay($PWLog, "Password Log") EndFunc ;==>PassGen Edited February 26, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Venix Posted February 26, 2013 Author Posted February 26, 2013 @JohnOne Always good to see a slightly different approach, I tried something similar earlier but was getting errors I must have been doing something wrong but now have 2 examples that work so that's great .
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now