Gerador de Senha

Publicado por Caio Marcus de Souza Dutra (última atualização em 13/05/2021)

[ Hits: 1.842 ]

Download keygen.c




Algoritmo simples que gera uma senha a partir de números, letras e símbolos aleatórios.

  



Esconder código-fonte

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

char key_range[77] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'Z',
'_', '.', '-', '$', '%', '/', '&', '(', ')', '[', ']', '?', '!', '@', '=', '+', '*' };

char * key_generate (int type, int qtd) {
               
      char * pass_generated;
      int x1 = 0, x2 = 0;
      
      pass_generated = (char *) malloc (qtd * sizeof (char));
      if (pass_generated == NULL) return (NULL);
      
      srand(time(NULL));
      
      /* Types:
         1 - Numbers only
         2 - Letters only
         3 - Numbers and Letters
         4 - Hard pass.
      */
      
      switch (type) {
         case 1: x1 = 0; x2 = 9;
            break;
         case 2: x1 = 10; x2 = 49;
            break;
         case 3: x1 = 0; x2 = 49;
            break;
         case 4: x1 = 0; x2 = 76;
            break;
         default:
            return (NULL);         
      }
      
      for (int n = 0; n < qtd; n++)
         pass_generated[n] = key_range[x1 + rand () % x2];
               
      return (pass_generated);
}

void clean_screen () {
   
   system("clear");
   printf ("**************************************************\n");
   printf ("** GENERATES A RANDOMIC KEY ** STRONG PASSWORD  **\n");
   printf ("**                                              **\n");
   printf ("**************************************************\n");
   printf ("\n");

}   

int main ( ) {
   
   int t, q;
   char * pass = NULL;
   
   while (1) {
      clean_screen();
      printf ("Choose your password type: \n");
      printf ("  1 - Numbers only;\n");
      printf ("  2 - Letters only;\n");
      printf ("  3 - Numbers and Letters;\n");
      printf ("  4 - Hard pass;\n");
      printf ("  0 - Let me out.\n");
      printf ("\n: ");
      scanf ("%d", &t);
      if (t == 0) return (0);
      
      printf ("Ok.. and how many characters? ");
      scanf ("%d", &q);
      if (q == 0) {
         printf ("I'm sorry! You can't generate a password with no characters...\n");
         printf ("Please, tell me again how many characters do you want for your password: ");
         scanf ("%d",&q);
         if (q == 0) {
            printf ("\nOk. We can't go on this way. I'm going to mom's and taking Jack with me. See you in hell..\n");
            getch();
            return (0);
         }
      }
      printf ("Ok... wait a minute while we generate your password... Here we go:\n");
            
      pass = key_generate (t, q);
      if (pass == NULL) 
         printf ("Oh, no! Something went wrong! I'm sorry, try again.\n");         
      else 
         for (int i = 0; i < q; i++)
            printf ("%c", pass[i]);
      
      free (pass);
      getch();      
   }
   return (0);
}

Scripts recomendados

É um programa de locação

Interpolação linear

Transformação linear

Calcula uma PA...

[C] Equação do 2° Grau


  

Comentários
[1] Comentário enviado por maurixnovatrento em 13/05/2021 - 20:45h


Bacana cara.

___________________________________________________________
[code]Conhecimento não se Leva para o Túmulo.
https://github.com/MauricioFerrari-NovaTrento [/code]


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts