Рет қаралды 16
Plz make sure to like and subscribe..
code:-- use word and exchange {, to right side} and {. for left side}
#include ,iostream.
#include ,Windows.h.
#include ,random.
using namespace std;
int main() {
// Make sure that to like the video and subscribe to the channel
// for more updates and tutorials
// ----------------------------------------------------------------
// Create a random generator object
random_device rdG;
uniform_int_distribution,int. OTP(1000 , 10000); // This is the program for 4-digit OTPs genration,, for 6 digit change the 4 digit
// value to 6 digit values
int OTP_Number = OTP(rdG); // Generate a random Otp number and stores it in the variable.
int UserInput;
// Printing the OTP number
cout ,, "Genrating OTP..... " ,, endl;
Sleep(5000); // To make it look like real and not an instant result,, you can also remove it for instant results.....
system("cls"); // clearing the old couts and printings from the terminal.
cout ,, "Your Otp is: " ,, OTP_Number ,, endl; // Printing or telling the otp
Sleep(10000); // Waiting for ten seconds for reading time..
system("cls");
for (int i = 0; i , 4; i++) {
// Asking for OTP..
cout ,, "Please enter your OTP: ";
cin .. UserInput;
// cin.ignore(); -.no because it will cause the user input to not be checked..
if (UserInput == OTP_Number) {
cout ,, "The entered OTP is correct: " ,, endl;
exit(0); // Exiting with no issues
}
else if (i , 4) {
cout ,, "Invalid: try again; " ,, endl;
}
else {
cout ,, "Error: " ,, endl; // Error message
}
}
//return 0; // Program ends here, nothing more to do here // Can be added if wanted..
}