#include <stdio.h> /* printf, fgets */ #include <stdlib.h> /* atoi */ #include <time.h> #include <string> #include <cstring> #include <math.h> #include <sstream> char * getTimeEncodeString(); bool login(char *pass_temp); int main (){ char pass_temp[7]="123456"; printf("%s\n",getTimeEncodeString()); printf("%d\n",login(pass_temp)); } bool login(char *pass_temp){ char *pass=getTimeEncodeString(); if(strcmp(pass_temp,pass)==0){ return true; }else{ return false; } } char * getTimeEncodeString(){ // 局部静态变量作为返回值 static char dest[7]; time_t rawtime; time( &rawtime ); struct tm *info; info = localtime( &rawtime ); char buffer[32]; // strftime(buffer, 32, "%Y-%m-%d %H:%M:%S", info); strftime(buffer, 32, "%m%d%H", info); // 字符串转 long long passlong = atoi(buffer); // 加密算法 passlong=passlong*137; char str_temp[10]; // long 转字符串 ltoa(passlong,str_temp,10); // 截取6个字符 strncpy(dest, str_temp, 6); return dest; }
C 语言登录的例子
猜你喜欢
转载自www.cnblogs.com/1886vip/p/11119705.html
今日推荐
周排行