演示在 DOS/控制台環境下,利用系統日期時間作為動態密碼的簡單驗證邏輯。密碼規則:月份 + 日期 + 小時(如 1月15日14時 → 1+15+14=30)。
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void main(void) {
struct date today;
struct time now;
getdate(&today);
gettime(&now);
textcolor(WHITE);
textbackground(BLUE);
do {
clrscr();
gotoxy(25, 10);
printf("today's date is %d-%d-%d", today.da_mon, today.da_day, today.da_year);
gotoxy(28, 12);
printf("the time is %2d:%2d:%2d", now.ti_hour, now.ti_min, now.ti_sec);
gotoxy(1, 1);
} while (atoi((char*)getpass("password:")) != today.da_mon + today.da_day + now.ti_hour);
textcolor(WHITE);
textbackground(BLACK);
clrscr();
gotoxy(1, 1);
printf(" ");
}
getdate/gettime:DOS 專用,獲取系統日期時間(dos.h)。getpass:無回顯讀取密碼輸入(返回靜態緩衝區指針)。atoi:將輸入字符串轉為整數參與驗證。textcolor/textbackground/clrscr/gotoxy:conio.h 控制台顏色與光標控制(Borland/Turbo C 風格)。SetConsoleTextAttribute、SetConsoleCursorPosition 替代 conio.h。termios 關閉回顯實現 getpass 效果。本程序僅為教學演示,不可用於實際安全場景:密碼極簡、明文邏輯、無加密、無防暴力破解機制。生產環境請使用成熟認證庫(如 OpenSSL、PAM)。