#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <curl/curl.h>
// Function to generate a 6-digit OTP
int generateOTP() {
return (rand() % 900000) + 100000; }
// Function to send the OTP via Twilio API
void sendOTP(const char* otp, const char* to_number, const char* from_number, const char* account_sid, const char* auth_token) {
CURL *curl;
CURLcode res;
// Initialize CURL
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
char url[256];
sprintf(url
, "https://a...content-available-to-author-only...o.com/2010-04-01/Accounts/%s/Messages.json", account_sid
);
// Message body
char data[512];
sprintf(data
, "To=%s&From=%s&Body=Your+OTP+is+%s", to_number
, from_number
, otp
);
// Set up the request
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
// Set authentication
char auth[128];
sprintf(auth
, "%s:%s", account_sid
, auth_token
); curl_easy_setopt(curl, CURLOPT_USERPWD, auth);
// Perform the request
res = curl_easy_perform(curl);
// Check for errors
if(res != CURLE_OK)
fprintf(stderr
, "curl_easy_perform() failed: %s\n", curl_easy_strerror
(res
)); else
printf("OTP sent successfully!\n");
// Cleanup
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}
int main() {
// Seed the random number generator
// Generate the OTP
int otp = generateOTP();
char otp_str[7];
// Twilio credentials and numbers
const char* account_sid = "your_account_sid";
const char* auth_token = "your_auth_token";
const char* to_number = "+9145815895"; // Replace with the recipient's number
const char* from_number = "+9718606781"; // Replace with your Twilio number
// Send the OTP
sendOTP(otp_str, to_number, from_number, account_sid, auth_token);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3VybC9jdXJsLmg+CgovLyBGdW5jdGlvbiB0byBnZW5lcmF0ZSBhIDYtZGlnaXQgT1RQCmludCBnZW5lcmF0ZU9UUCgpIHsKICAgIH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ICIrOTE0NTgxNTg5NSI7ICAgICAvLyBSZXBsYWNlIHdpdGggdGhlIHJlY2lwaWVudCdzIG51bWJlcgogICAgY29uc3QgY2hhciogZnJvbV9udW1iZXIgPSAiKzk3MTg2MDY3ODEiOyAgIC8vIFJlcGxhY2Ugd2l0aCB5b3VyIFR3aWxpbyBudW1iZXIKCiAgICAvLyBTZW5kIHRoZSBPVFAKICAgIHNlbmRPVFAob3RwX3N0ciwgdG9fbnVtYmVyLCBmcm9tX251bWJlciwgYWNjb3VudF9zaWQsIGF1dGhfdG9rZW4pOwoKICAgIHJldHVybiAwOwp9
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <curl/curl.h>
// Function to generate a 6-digit OTP
int generateOTP() {
return (rand() % 900000) + 100000;
}
// Function to send the OTP via Twilio API
void sendOTP(const char* otp, const char* to_number, const char* from_number, const char* account_sid, const char* auth_token) {
CURL *curl;
CURLcode res;
// Initialize CURL
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
char url[256];
sprintf(url, "https://a...content-available-to-author-only...o.com/2010-04-01/Accounts/%s/Messages.json", account_sid);
// Message body
char data[512];
sprintf(data, "To=%s&From=%s&Body=Your+OTP+is+%s", to_number, from_number, otp);
// Set up the request
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
// Set authentication
char auth[128];
sprintf(auth, "%s:%s", account_sid, auth_token);
curl_easy_setopt(curl, CURLOPT_USERPWD, auth);
// Perform the request
res = curl_easy_perform(curl);
// Check for errors
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else
printf("OTP sent successfully!\n");
// Cleanup
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}
int main() {
// Seed the random number generator
srand(time(NULL));
// Generate the OTP
int otp = generateOTP();
char otp_str[7];
sprintf(otp_str, "%d", otp);
// Twilio credentials and numbers
const char* account_sid = "your_account_sid";
const char* auth_token = "your_auth_token";
const char* to_number = "+9145815895"; // Replace with the recipient's number
const char* from_number = "+9718606781"; // Replace with your Twilio number
// Send the OTP
sendOTP(otp_str, to_number, from_number, account_sid, auth_token);
return 0;
}