Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
a e i o u b c d f g h j k l m n p q r s t v w x y z |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
#include <iostream> #include <string> #include <ctime> #include <cstdlib> #include <cstdio> #include <fstream> using namespace std; void generator () { foobar: string dateiname=("konfig.txt"); ifstream dat_ein; dat_ein.open(dateiname.c_str(), ios_base::in); if(!dat_ein) //Hier sollte sich das Proggam nach Tastendruck schliessen, //Wenn die Datenbank nicht existiert //Wie geht das aber?? { system ("cls"); cout << "Fehler beim Aufruf von 'konfig.txt.'! \a " <<endl; fflush (stdin); getchar(); } char V[6]; char K[6]; int datensatz; int loop; for (int i = 1; i <= 6; ++i) //Generator für die Vokale { srand( (unsigned) time (NULL) ); datensatz = rand()%5+1; loop = datensatz; while(loop>=1) { dat_ein>>V[i]; -- loop; } } for ( i = 7; i <= 12; ++i) //Generator für die Konsonanten { srand( (unsigned) time (NULL) ); datensatz = rand()%26+6; loop = datensatz; while(loop>=1) { dat_ein>>K[i]; -- loop; } } cout<<endl<<endl<<"Erstelltes Passwort: "; cout<<K[1]<<V[1]<<K[2]<<V[2]<<K[3]<<V[3]<<K[4]<<V[4]<<K[5]<<V[5]<<K[6]<<V[6]; loop: cout<<endl<<endl<<"(N)eues Passwort generieren"<<endl; cout<<"(B)eenden"<<endl; char c; cin>>c; if ( c=='N' || c=='n' ) { goto foobar; } if ( c=='B' || c=='b' ) { cout<<"ENDE"<<endl; //Hier weiss ich nicht, wie ich das Programm aus der Funktion, beenden kann... } if( c!='B' || c!='b' || c!='N' || c!='n' ) { goto loop; } } int main () { foobar: system ("cls"); cout<<"Willkommen bei Passgen! Der Passwortgenerator des Jahrhunderts!"<<endl; cout<<" Made by Alexander Stepanov!"<<endl; cout<<"_______________________________________________________________"<<endl; cout<<endl<<endl<<endl<<endl<<endl<<endl; cout<<"(P)asswort generieren"<<endl; cout<<"(A)nleitung"<<endl; char a; cin>>a; if ( a=='a' || a=='A' ) { loop: char w; cout<<endl<<endl<<endl; cout<<"Anleitung: "<<endl; cout<<" Dieses Programm generiert Passwörter die "<<endl; cout<<" 12 Zeichen lang sind. Die Passwörter kann "<<endl; cout<<" man sich sehr leicht merken. "<<endl; cout<<" Um ein Passwort zugenerieren druecken Sie "<<endl; cout<<" auf 'P' beim Menue, danach wird das "<<endl; cout<<" Passwort generiert."<<endl; cout<<endl<<endl<<"(Z)urueck"<<endl; cin>>w; if ( w!='Z' || w!='z' ) goto foobar; else goto loop; } else if ( a=='P' || a=='p' ) { generator(); } else if ( a=='B' || a=='b' ) { return -1; } else { goto foobar; } return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
void generate_password(const std::string& config_file, std::size_t len, std::string& pass) { pass = ""; std::ifstream file_stream(config_file.c_str(), std::ios::in); if (!file_stream) throw std::runtime_error(std::string("File does not exist! => ") + config_file); std::vector<char> static_values; char val = 0; while ((file_stream >> val)) static_values.push_back(val); for (std::size_t i = 0; i < len; ++i) pass[i] = (i % 2 ? static_values[i % static_values.size()] : std::rand() % 25 + 65 /* 65 - 90 == Großbuchstaben! */); } |
Werbeanzeige