To Generate a One Time Password or Unique Identification URL | A C / C ++ Program to generate OTP ( One Time Password ) ; A Function to generate a unique OTP everytime ; All possible characters of my OTP ; String to hold my OTP ; Driver Program to test above functions ; For different values each time we run the code ; Declare the length of OTP
#include <bits/stdc++.h> NEW_LINE using namespace std ; string generateOTP ( int len ) { string str = " abcdefghijklmnopqrstuvwxyzABCD " " EFGHIJKLMNOPQRSTUVWXYZ0123456789" ; int n = str . length ( ) ; string OTP ; for ( int i = 1 ; i <= len ; i ++ ) OTP . push_back ( str [ rand ( ) % n ] ) ; return ( OTP ) ; } int main ( ) { srand ( time ( NULL ) ) ; int len = 6 ; printf ( " Your ▁ OTP ▁ is ▁ - ▁ % s " , generateOTP ( len ) . c_str ( ) ) ; return ( 0 ) ; }