#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
FILE *file;
char ulang,username[10],password[10],user[10],pass[10],userbaru[10],passbaru[10];
int menu_login,userbenar,passbenar;
void masukanuser(){
file=fopen("gantiuser.txt","r");
fscanf(file,"%s",username);
fclose(file);
}
void masukanpass(){
file=fopen("gantipass.txt","r");
fscanf(file,"%s",password);
fclose(file);
}
void menu_admin(){
printf("\t\t\t\t\tMenu Login");
printf("\n1. Login");
printf("\n2. Ganti Password");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &menu_login);
switch(menu_login){
case 1 :
login();
break;
case 2 :
userpass();
break;
}
}
void login(){
do{
system("cls");
printf("\t\t\t\tMenu Admin\n\n");
printf("Username : ");
masukanuser();
scanf("%s",&user);
userbenar=strcmp(user, username);
printf("Password : ");
masukanpass();
scanf("%s",&pass);
passbenar=strcmp(pass, password);
if(userbenar!=0||passbenar!=0){
printf("User/Pass Salah\n");
system("pause");
}
else {
printf("Login Berhasil\n");
system("pause");
}
} while(strcmp(user,username)!=0||strcmp(pass,password)!=0);
system("cls");
}
void userpass(){
do{
system("cls");
printf("Ganti Username dan Password");
printf("\n\nMasukan Username Lama : ");
masukanuser();
scanf("%s",user);
printf("\nMasukan Password Lama : ");
masukanpass();
scanf("%s",pass);
userbenar=(strcmp(user,username));
passbenar=(strcmp(pass,password));
if(userbenar==0||passbenar==0){
system("cls");
printf("Ganti Username dan Password");
printf("\n\nMasukan Username Baru : ");
scanf("%s",userbaru);
file=fopen("gantiuser.txt","w");
fprintf(file,"%s",userbaru);
fclose(file);
printf("\nMasukan Password Baru : ");
scanf("%s",passbaru);
file=fopen("gantipass.txt","w");
fprintf(file,"%s",passbaru);
fclose(file);
printf("Username dan Password Sukses Diganti");
printf("\nData Sudah Tersimpan\n");
system("pause");
system("cls");
login();
}else{
printf("Username dan Password Salah!!!");
printf("\n\nIngin Coba Lagi? [y/n]:");
ulang=getch();
system("cls");
main();
}
}while(ulang=='y');
}
nb : -kalian harus buat dulu file .txt gantipass dan gantiuser serta tulis password dan username awalnya di file .txt tersebut
-lalu kalian bisa memanggilnya di program yang kalian miliki
Sekian artikel dari saya, semoga bermanfaat.
Terimakasih