I wrote a password poor, you can set a password character, set the password that starts exhaustion, and provides the progress of the progress of the progress.
Below is the code
#include
#include
#include <
String>
#define charnum 62
Using
Namespace
STD;
Class Xkpassword {
PUBLIC:
Xkpassword
int Digit;
~ xkpassword ();
String xkpassword :: getnewpass ();
Bool setpass
String);
String getpass ();
Bool save ();
Bool load ();
Private:
Char PWD [charnum];
String currentpassword;
Char * filename;
Int getcharpos
charr
CH);
}
Xkpassword :: ~ xkpassword () {
DELETE [] FileName;
}
Xkpassword :: xkpassword
INT DIGIT {
Filename =
New
CHAR [20];
STRCPY (FileName,
"DATA.DAT");
IF (Digit <1) DIGIT = 1;
// Password characters used
STRCPY (PWD,
"0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
CurrentPassword.Append (Digit, '0');
}
Bool xkpassword :: save () {
OFSTREAM
OUT (filename);
IF (!
OUT
Return
False;
OUT << CurrentPassword;
Out.close ();
Return
True;
}
Bool xkpassword :: loading () {
IFStream
In (filename);
IF (!
in)
Return
False;
CurrentPassword;
In.Close ();
Return
True;
}
INT Xkpassword :: getcharpos
charr
CH) {
INT C = 0;
For (; c IF (PWD [C] == CH) Break; Return C; } String xkpassword :: getpass () { Return CurrentPassword; } Bool xkpassword :: setpass String pass) { Basic_string < Char> :: item POS; For (POS = Pass.begin (); POS! = pass.end (); POS ) IF (GetCharpos (* POS) == Charnum) Return False; CurrentPassword = pass; Return True; } String xkpassword :: getnewpass () { Basic_string < Char> :: item POS; Int charpos; POS = CurrentPassword.end () - 1; Charpos = getcharpos (* POS); // cout << "endchar" << * POS << Endl; // cout << "charpos" << charpos << Endl; IF ((Charpos 1) * POS = PWD [Charpos 1]; Else { * POS = PWD [0]; WHILE True) { IF (POS == CurrentPassword.begin ()) { CurrentPassword.Insert (POS, PWD [0]); Break; } POS - Charpos = getcharpos (* POS); IF ((Charpos 1) == Charnum) { * POS = PWD [0]; CONTINUE; } Else { * POS = PWD [Charpos 1]; Break; } } } Return CurrentPassword; } INT FINDCHAR charr CH, Char a []) { INT LEN = SizeOf (a) / Sizeof Char); INT C = 0; For (; C IF (a [c] == CH) Break; } Return C; } / * int main () {xkpassword pw (1); int C = 0; PW.LOAD (); cout << pw.getpass () << "; for (;; c <2000; c ) cout << PW .getnewpass () << ""; if (! pw.save ()) cout << "Unable to write file:" << endl; return 0;} * /