Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random 12digit password generator

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I need something that'll create a quick alphanumeric(a-&gt;z, A-&gt;Z, 1-&gt;0) 12 digit character array<br>
something i can just throw in a char something[13];<br>
<p>Karl<br><a href=mailto:kb244@bellsouth.net>kb244@bellsouth.net</a><br><a href= </a><br>
 
Ok i looked into it, got something made, tho microsoft MSDN was no help at all, and i do remeber there used to be a random command where you just stick in the ranges, but M$ had no info on this instead i came up with this lil example<br>
<br>
#include &lt;iostream.h&gt;<br>
#include &lt;stdlib.h&gt;<br>
#include &lt;stdio.h&gt;<br>
#include &lt;time.h&gt;<br>
<br>
void main( void )<br>
{<br>
int i,j; char tmp[13];<br>
i=j=0;<br>
srand( (unsigned)time( NULL ) );<br>
for( i = 0; i &lt;= 12;i++ )<br>
{<br>
<br>
while((j&lt;48) ¦¦ ((j&gt;57)&&(j&lt;65)) ¦¦ ((j&gt;90)&&(j&lt;97)) ¦¦ (j&gt;122))<br>
{<br>
j = rand();<br>
}<br>
tmp<i> = j;<br>
cout&lt;&lt;j&lt;&lt;' ';<br>
j=0;<br>
}<br>
tmp[13]='\0';<br>
cout&lt;&lt;'\n'&lt;&lt;tmp;<br>
}<br>
/*<br>
48-&gt;57 numbers<br>
65-&gt;90 capital letters<br>
97-&gt;122 lowercase letters<br>
*/ <p>Karl<br><a href=mailto:kb244@bellsouth.net>kb244@bellsouth.net</a><br><a href= </a><br>
 
Hi Kb244,<br>&nbsp;&nbsp;&nbsp;When I ran your code . It was not working properly. But the problem is interesting , so I dared to try it out. I 've pasted the code below. Please have a look over it Also I made a change in for loop because if you go for 0 to 12 , it is actually 13 byte long password . But you want to generate for 12 only. Although you've explicitly pushing null at 13th position. <br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br><br>#include &lt;iostream.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;time.h&gt;<br>void main( void ) {<br>int i,j; <br>char temp[13];<br>srand( (unsigned)time( NULL ) );<br>/* For twelve no. it should start from 0 to 11. */<br>for( i = 0; i &lt; 12;i++ ) {<br> switch(j=rand() % 3) {&nbsp;&nbsp;/* Random for small,capital and numbers */<br> case 0: /* For small letters&nbsp;&nbsp;&nbsp;&nbsp;*/<br> j = 48 + rand() % 10;<br> temp<i> = (char) j;<br> break;<br> case 1: /* For capital letters&nbsp;&nbsp;*/<br> j = 65 + rand() % 26;<br> temp<i> = (char) j;<br> break;<br> case 2: /* For Numbers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br> j = 97 + rand() % 26;<br> temp<i> = (char) j;<br> break;<br> } /* End Switch */<br>} /* End For */<br><br>temp<i>='\0';<br>cout&lt;&lt;'\n'&lt;&lt;&quot;The password:&quot; &lt;&lt;temp &lt;&lt; '\n';<br>return ;<br>}<br><br>/*<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;48-&gt;57 numbers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;65-&gt;90 capital letters<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;97-&gt;122 lowercase letters<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/ <br>
 
i ran the program and it worked...<br>i don't understand HOW to actually implement this generator in a larger or FOR WHAT reason?
 
The reason might be anything . Either for an assignment, or for your own interest , etc... This is the way to learn more and more<br><br>siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br>
 
I've done something like this, and here was my approach (this is just pseudocode):<br><br>char lpPasswordChars [32] = &quot;abcdefghijkl&quot;;<br><br>void GenPassword (char * buffer)<br>{<br>&nbsp;&nbsp;&nbsp;char lpPassword[12];<br>&nbsp;&nbsp;&nbsp;&nbsp;for (i = 0; i &lt; 12; i++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;//create a random number <br>&nbsp;&nbsp;&nbsp;&nbsp;int foo = rand()*1000;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//use it to index into the array<br>&nbsp;&nbsp;&nbsp;&nbsp;lpPassword<i> = lpPasswordChars[foo%11];<br>&nbsp;&nbsp;&nbsp;}<br>}<br><br>The idea is to use a random index to an array.&nbsp;&nbsp;Now you can control exactly the character set that will be drawn from without worrying about ASCII values or ranges.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top