Advertisement
florin88

Generatore di Password

Feb 12th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. /*************************************************************/
  2. /*Nome Prog:  Generatore di Password                     */
  3. /*Questo semplice programma in C++, ti consente di generare */                                                  
  4. /*in modo autonomo password di tipo:                          */
  5. /*1-Alphanumerici (a-z,A-Z,0-9)                   */
  6. /*2-Solo Lettere                          */
  7. /*3-Solo Numeri                           */
  8. /*4-In base alle tue esigenze                     */
  9. /*Autore: florin88                                    */
  10. /*e-mail: ffinformaticus@gmail.com                    */
  11. /***********************************************************/
  12.  
  13.  
  14. #include<iostream>
  15. #include<stdlib.h>
  16. #include<time.h>
  17. #include<string.h>
  18.  
  19. using namespace std;
  20.  
  21.     int main()
  22.     {
  23.        int length,x,str,j=0,answ;
  24.        char pass[255],s[255],
  25.        alphan[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  26.        alph[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  27.        num[]="0123456789";
  28.  
  29.       cout<<"##################################"<<endl;
  30.      
  31.        cout<<"Seleziona il tipo di password che vuoi generare: \n1-Alphanumerici (a-z,A-Z,0-9) \n2-Solo Lettere \n3-Solo Numeri  \n4-Dai le tue direttive \nNUMERO della Funzione da utilizzare: ";
  32.        cin>>answ;
  33.  
  34.       cout<<"##################################"<<endl;
  35.  
  36.    
  37.        if(answ==4)
  38.        {
  39.           cout<<"Scrivi i caratteri che vuoi usare per la tua PASSWORD (senza lasciare spazi tra i caratteri): ";
  40.           cin>>s;
  41.           str=strlen(s);
  42.        }
  43.        cout<<"Quanto lunga deve essere la tua password? => ";
  44.        cin>>length;
  45.        srand(time(NULL));
  46.        switch(answ)
  47.        {
  48.           case 1:{while(length--)
  49.                       {
  50.                          x=rand()%62;
  51.                          pass[j++]=alphan[x];
  52.                       }
  53.                    } break;
  54.           case 2:{while(length--)
  55.                       {
  56.                          x=rand()%52;
  57.                          pass[j++]=alph[x];
  58.                       }
  59.                    } break;
  60.           case 3:{while(length--)
  61.                       {
  62.                          x=rand()%10;
  63.                          pass[j++]=num[x];
  64.                       }
  65.                    } break;
  66.           case 4:{while(length--)
  67.                       {
  68.                          x=rand()%str;
  69.                          pass[j++]=s[x];
  70.                       }
  71.                    } break;
  72.        }
  73.      
  74.        cout<<"Ecco qui la tua PASSWORD: ";
  75.        for(int i=0;i<j;i++)
  76.           cout<<pass[i];
  77.        cout<<endl;
  78.        cout<<"##################################"<<endl;
  79.        return 0;
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement