当前位置:网站首页>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 .
边栏推荐
- Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
- Zzuli:1046 product of odd numbers
- Luogu p5194 [usaco05dec]scales s solution
- Programming language: the essence of type system
- Zzuli:1041 sum of sequence 2
- Pyqt interface production (login + jump page)
- Zzuli:1053 sine function
- Zzuli:1057 prime number determination
- 修改数据库中的记录为什么报这个错
- Luogu p3065 [usaco12dec]first! G problem solution
猜你喜欢

tonybot 人形机器人 红外遥控玩法 0630

Use of constraintlayout

Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解

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

Sword finger offer 28 Symmetric binary tree

How to query the baby category of tmall on Taobao

dllexport和dllimport

编程语言:类型系统的本质
随机推荐
7-1 positive integer a+b (15 points)
7-23 currency conversion (using array conversion)
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Output student grades
Doris学习笔记之数据表的创建
Common commands for getting started with mongodb database
How Facebook moves instagram from AWS to its own server
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
ShowMeBug入驻腾讯会议,开启专业级技术面试时代
Ultra simple mobile map development
retrofit
分布式事务(Seata) 四大模式详解
Find the sum of the elements of each row of the matrix
JVM garbage collector
Dllexport and dllimport
Zzuli:1057 prime number determination
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
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
tonybot 人形机器人 红外遥控玩法 0630
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库