当前位置:网站首页>C language to implement a password manager (under update)
C language to implement a password manager (under update)
2022-07-03 14:36:00 【roseisbule】
As a computer enthusiast , Will often register various website accounts , But considering the possible leakage of privacy , Don't like hosting passwords to browsers , So often forget all kinds of passwords . After suffering , I decided to learn a little c Language knowledge to write a password manager .
Before writing, I hope it can realize the following functions :
1. Be able to write a new password , And save the time and date when writing the password .
2. Can find the password , When you can't find an account that fully matches the characteristics , Can remind me of the most similar account .
3. Be able to change the password of a certain account type , When modifying , Synchronize the time of modification .、
4. The stored data is divided into four parts , The first is the account type , Such as :wechat, The second is account , The third is the account and password , The fourth is the last storage , Or the standard time of modification .
5. Be able to list all account types , For me to read .
6. All stored data should be randomly encrypted , When reading, it can decrypt according to the random key .
After figuring out the function , We need to imagine using the process , first , You must log in , If you haven't logged in before , Then you need to register .
Part of the code is as follows :
int jianchadengru()
{
char arr1[100] = { 0 };
char arr2[100] = { 0 };
char count[100] = { 0 };
char pass[100] = { 0 };
char date[100] = { 0 };
char type[100] = { 0 };
char mystring[400] = { 0 };
FILE* pf = fopen("test.txt", "r");
fgets(mystring, 400, pf);
fclose(pf);
jiemi(type, arr1, arr2, date, mystring);
//printf("%s", type);
printf(" Enter your account number :");
scanf("%s", &count);
printf(" Enter your password :");
scanf("%s", &pass);
if (strcmp(count, arr1) == 0 && strcmp(pass, arr2) == 0 && strcmp(type, "admin") == 0)
return 1;
return 0;
}After go in , Need to write a simple menu .
void onlymenu()
{
printf("---------------------------------------\n");
printf("----- Password trustee ------\n");
printf("----- 1. Write new password ------\n");
printf("----- 2. Find a password ------\n");
printf("----- 3. Modify an account ------\n");
printf("----- 4. See all accounts ------\n");
printf("----- 0. Exit procedure ------\n");
printf("---------------------------------------\n");
printf("---------------------------------------\n");
printf("---------------------------------------\n");
}
void menu()
{
onlymenu();
int i = 0;
do
{
printf("\n Please select :");
scanf("%d", &i);
int k = 0;
switch (i)
{
case 1:
add_count();
break;
case 2:
chazhao();
break;
case 3:
xiugai();
break;
case 4:
check_all();
break;
case 0:
return;
default:
printf(" Wrong choice \n");
break;
}
} while (i);
}Writing a new password is relatively simple , Just add write ok.
void add_count()
{
while (1)
{
char flag[20] = { 0 };
char count[100] = { 0 };
char pass[100] = { 0 };
char type[100] = { 0 };
printf(" Enter the account type you want to add ( Do not include spaces , Not more than 100 Characters ):");
scanf("%s", &type);
printf(" Enter the account you want to add ( Do not include spaces , Not more than 100 Characters ):");
scanf("%s", &count);
printf(" Enter the password of the account you want to add ( Do not include spaces , Not more than 100 Characters ):");
scanf("%s", &pass);
printf(" The account type you added is :%s, Account No :%s, The password for :%s\n Are you sure (YES):",type, count, pass);
scanf("%s", &flag);
if (strcmp(flag, "YES") == 0)
{
xieru(type, count, pass);
printf(" Write successfully !");
break;
}
}
}void put_time(char ltime[100], int* i, int time_flag)
{
ltime[*i] = time_flag / 10 + '0';
(*i)++;
ltime[*i] = time_flag % 10 + '0';
(*i) += 3;
}
void get_time(char ltime[100])
{
time_t timep;
struct tm* p;
time(&timep);
p = gmtime(&timep);
int i = 0;
int year = 1900 + p->tm_year;
while (year > 0)
{
ltime[i] = (year % (int)pow(10, 4 - i)) / (int)pow(10, 3 - i) + '0';
i++;
year = year % (int)pow(10, 4 - i);
}
strcat(ltime, " year ");
i += 2;
char* week[7] = { " Monday "," Tuesday "," Wednesday "," Thursday "," Friday "," Saturday "," Sunday " };
put_time(ltime, &i, 1 + p->tm_mon);
strcat(ltime, " month ");
put_time(ltime, &i, p->tm_mday);
strcat(ltime, " Japan ");
i += 6;
strcat(ltime, week[p->tm_wday]);
put_time(ltime, &i, p->tm_hour + 8);
strcat(ltime, " when ");
put_time(ltime, &i, p->tm_min);
strcat(ltime, " branch ");
put_time(ltime, &i, p->tm_sec);
strcat(ltime, " second ");
}
void xieru(char type[100],char count[100],char pass[100])
{
FILE* pf = fopen("test.txt", "a");
int code1 = readom();
char ltime[100] = { 0 };
get_time(ltime);
jiami(ltime, (int)strlen(ltime), code1);
jiami(count, (int)strlen(count), code1);
jiami(pass, (int)strlen(pass), code1);
jiami(type, (int)strlen(type), code1);
char code = code1 + '0';
fputc(code, pf);
fputc(';', pf);
fputs(type, pf);
fputc(';', pf);
fputs(count, pf);
fputc(';', pf);
fputs(pass, pf);
fputc(';', pf);
fputs(ltime, pf);
fputc('\n', pf);
fclose(pf);
}In this way, the writing automatically adds the system time .
Then there is the lookup function .
Lookup function , My idea is this , If you can find an account that fully matches the characteristics , Then there is no need to look down , If you don't find a perfect match , Then create an array , Record the overlapping size of each account and search account , Take the maximum to prompt .
int findmax(int arr[100])
{
int i = 0;
int max = 0;
int max_i = 0;
for (i = 0; i < 100; i++)
{
if (arr[i] > max)
{
max_i = i;
max = arr[i];
}
}
return max_i;
}
void chazhao()
{
char count[30][100] = { 0 };
char pass[30][100] = { 0 };
char type[30][100] = { 0 };
char date[30][100] = { 0 };
FILE* pf = fopen("test.txt", "r");
char mystring[400] = {0};
int i = 0;
int j = 0;
int tmp = 0;
if (pf == NULL)
{
printf(" Missing key files , Program error , Please contact the developer .\n");
system("pause");
return;
}
else
{
while (fgets(mystring, 400, pf) != NULL)
{
jiemi(type[i],count[i], pass[i],date[i], mystring);
i++;
}
fclose(pf);
}
int flag[100] = { 0 };
while (1)
{
printf(" Please enter the account type you want to find :");
char count1[100] = {0};
scanf("%s", &count1);
tmp = i;
int coin = 0;
for (i = 0; i < tmp; i++)
{
if (strcmp(count1, type[i]) == 0)
{
coin = 1;
printf(" Account No :%s\n The password for :%s\n",count[i], pass[i]);
return;
}
else
{
for (j = 0; j < 100; j++)
{
if (type[i][j] == count1[j] && j < strlen(count1) && j < strlen(type[i]))
{
flag[i]++;
}
}
}
}
if (coin != 1)
{
printf(" The account that fully matches the characteristics is not found \n The program guesses that you are looking for :%s Type account \n", type[findmax(flag)]);
}
}
}Then modify the function , We can modify it like this , First write the modified value to the original file , Then find the location of the account number to be modified in the original file , Then create a new file , Copy the original file , But when it comes to modifying the location of the account , Just skip. .
void xiugai()
{
int i = 0;
while (1)
{
char type[100] = { 0 };
char count[100] = { 0 };
char pass[100] = { 0 };
char date[100] = { 0 };
int notice = 0;
char arr[100] = { 0 };
printf(" Please enter the account type to be modified :");
scanf("%s", &arr);
if (strcmp("admin",arr) == 0)
{
printf(" Modification of login account is not supported for the time being \n");
return;
}
i = 0;
int tmp = 0;
int j = 0;
FILE* pf = fopen("test.txt", "r");
if (pf == NULL)
{
printf(" Missing key files , Please contact the developer .");
return;
}
char mystring[400] = { 0 };
while (fgets(mystring, 400, pf) != NULL)
{
char count_tmp[100] = { 0 };
int key = mystring[0] - '0';
for (j = 2, tmp = 0; mystring[j] != ';'; j++, tmp++)
count_tmp[tmp] = mystring[j] + key;
if (strcmp(count_tmp, arr) == 0)
{
notice = 1;
fclose(pf);
jiemi(type, count, pass, date, mystring);
break;
}
else
i++;
}
fclose(pf);
if (notice == 0)
{
printf(" No fully matching account was found \n Please check this account first , Then enter the exact name !\n");
return;
}
else
{
char typetmp[100] = { 0 };
char counttmp[100] = { 0 };
char passtmp[100] = { 0 };
printf(" Please enter why you want to change the account type ( If it is not modified, enter quit):");
scanf("%s", &typetmp);
if (strcmp(typetmp, "quit") == 0)
strcpy(typetmp, type);
printf(" Please enter the reason for modifying the account ( If it is not modified, enter quit):");
scanf("%s", &counttmp);
if (strcmp(counttmp, "quit") == 0)
strcpy(counttmp, count);
printf(" Please enter the reason for changing the password ( If it is not modified, enter quit):");
scanf("%s", &passtmp);
if (strcmp(passtmp, "quit") == 0)
strcpy(passtmp, pass);
xieru(typetmp,counttmp,passtmp);
break;
}
}
move(i);
printf(" Modification successful !\n2s After the return \n");
Sleep(2000);
system("cls");
onlymenu();
}
void move(int i)
{
FILE* pf = fopen("test.txt", "r");
FILE* pf1 = fopen("tmp.txt", "w");
char mystring[400] = { 0 };
int j = 0;
int flag = i;
for (i = 0; fgets(mystring, 400, pf) != NULL; i++)
if (i != flag)
fputs(mystring, pf1);
fclose(pf);
fclose(pf1);
//fclose("test.txt");
remove("test.txt");
rename("tmp.txt","test.txt");
}Then there is the function that displays all accounts , This is the simplest .
void check_all()
{
char type[30][100] = { 0 };
char date[30][100] = { 0 };
char pass[30][100] = { 0 };
char count[30][100] = { 0 };
FILE* pf = fopen("test.txt", "r");
char mystring[400] = { 0 };
int i = 0;
int tmp = 0;
if (pf == NULL)
{
printf(" Missing key files , Program error , Please contact the developer .(qq:2898239515)\n");
system("pause");
return;
}
else
{
while (fgets(mystring, 400, pf) != NULL)
{
jiemi(type[i], count[i], pass[i], date[i], mystring);
i++;
}
fclose(pf);
}
printf(" The account you are hosting here has the following :\n");
printf(" Account type ---- The last time the account was saved or modified \n");
for (tmp = 0; tmp < i; tmp++)
{
printf("%s", type[tmp]);
printf(" ");
printf("%s\n", date[tmp]);
}
}Next is the most critical random encryption and decryption function , My current idea is to generate 10 A random number within is used as the random key , Then subtract the random number from all the characters , Get a new character , The whole data is encrypted . When decrypting , Read this key , Then add it back , It's solved .( Of course, I think this encryption method is very simple , I may use a more complicated encryption method later )
If the audience wants to experience , You can ask me for exe Oh .
边栏推荐
- Optical cat super account password and broadband account password acquisition
- Find books ()
- J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
- Zhejiang University Edition "C language programming (4th Edition)" topic set reference ideas set
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- Accelerating strategy learning using parallel differentiable simulation
- To improve efficiency or increase costs, how should developers understand pair programming?
- Sendmail can't send mail and it's too slow to send. Solve it
- 数学常数表 by q779
- Zzuli:1047 logarithmic table
猜你喜欢

天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million

论文分享:Generating Playful Palettes from Images

Use of constraintlayout

编程语言:类型系统的本质

基因家族特征分析 - 染色体定位分析

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue

Happy capital new dual currency fund nearly 4billion yuan completed its first account closing

Doris学习笔记之数据表的创建

Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
随机推荐
Etcd cluster permission management and account password usage
Detailed explanation of four modes of distributed transaction (Seata)
String reverse order
Too many files with unapproved license
Zzuli:1045 numerical statistics
7-14 sum integer segments (C language)
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Sword finger offer 28 Symmetric binary tree
Common commands for getting started with mongodb database
Four data flows and cases of grpc
Zzuli:1043 max
Get permissions dynamically
Ultra simple mobile map development
Tonybot humanoid robot infrared remote control play 0630
Zzuli:1057 prime number determination
7-20 print 99 formula table (format output)
tonybot 人形機器人 紅外遙控玩法 0630
adc128s022 ADC verilog设计实现
Showmebug entered Tencent conference, opening the era of professional technical interview
Puzzle (016.4) domino effect