In this program we can access the contents of a file after entering the correct OTP ,which will be given by the program itself and that OTP will we different each time.
-1680763532-1646.png)
Here a string is defined that contains letters from A-Z.a-z,0-9, so by using the letters of this string random opts will be generated under function give_otp().
1) Usage of rand()- It is an inbuilt function in header file. It is used to generate random numbers. After generating a sequence of characters those characters are pushed into a string named as result.
2) Access_file() function is used to show the content of the file in reading mode only and for that reason ios::in is used under fstream class.
-1680763593-1646.png)
3) Here, a function is called which will return the otp.
4)Srand() function is used to initialize those random numbers given by rand().
Generated nos.
****If only rand() is used, ------------------> 5 5 5
****If both rand() + srand()------------------>4 13 2
-1680763623-1646.png)
4) It is a simple switch case that will allow a user to access a file if the entered otp matches with the OTP provided by the program or you can exit the program or can ask for a new OTP.
Submitted by Muskan Chaturvedi (Muskan01)
Download packets of source code on Coders Packet
Comments