diff --git a/www/cgi-bin/c_mysql_user_pwd.c b/www/cgi-bin/c_mysql_user_pwd.c old mode 100644 new mode 100755 index d4d9f68..1a2e5a6 --- a/www/cgi-bin/c_mysql_user_pwd.c +++ b/www/cgi-bin/c_mysql_user_pwd.c @@ -8,20 +8,23 @@ #include #include -int main() { +int main() +{ // 连接到 MySQL 数据库 MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; conn = mysql_init(NULL); - if (conn == NULL) { + if (conn == NULL) + { fprintf(stderr, "mysql_init() failed\n"); exit(1); } if (mysql_real_connect(conn, "localhost", "root", "root", "router", 3306, - NULL, 0) == NULL) { + NULL, 0) == NULL) + { fprintf(stderr, "mysql_real_connect() failed\n"); mysql_close(conn); exit(1); @@ -33,7 +36,8 @@ int main() { // 解析 JSON 数据 cJSON *p = cJSON_Parse(request_data); - if (p == NULL) { + if (p == NULL) + { fprintf(stderr, "Error parsing JSON data\n"); mysql_close(conn); return 1; @@ -44,7 +48,8 @@ int main() { cJSON *pwd = cJSON_GetObjectItemCaseSensitive(p, "pwd"); if (user == NULL || pwd == NULL || !cJSON_IsString(user) || - !cJSON_IsString(pwd)) { + !cJSON_IsString(pwd)) + { fprintf(stderr, "Error getting username and/or password from JSON data\n"); cJSON_Delete(p); @@ -60,7 +65,8 @@ int main() { sprintf(query, "SELECT * FROM users WHERE username='%s' AND password='%s'", username_from_frontend, password_from_frontend); - if (mysql_query(conn, query)) { + if (mysql_query(conn, query)) + { fprintf(stderr, "SELECT query failed. Error: %s\n", mysql_error(conn)); cJSON_Delete(p); mysql_close(conn); @@ -68,7 +74,8 @@ int main() { } res = mysql_store_result(conn); - if (res == NULL) { + if (res == NULL) + { fprintf(stderr, "mysql_store_result() failed\n"); cJSON_Delete(p); mysql_close(conn); @@ -77,10 +84,13 @@ int main() { cJSON *result_json = cJSON_CreateObject(); - if ((row = mysql_fetch_row(res))) { + if ((row = mysql_fetch_row(res))) + { cJSON_AddNumberToObject(result_json, "code", 0); cJSON_AddStringToObject(result_json, "nickname", "admin"); - } else { + } + else + { cJSON_AddNumberToObject(result_json, "code", 1); cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误"); } diff --git a/www/cgi-bin/creat_table.sql b/www/cgi-bin/creat_table.sql old mode 100644 new mode 100755 diff --git a/www/cgi-bin/login.c b/www/cgi-bin/login.c new file mode 100755 index 0000000..300a4ba Binary files /dev/null and b/www/cgi-bin/login.c differ diff --git a/www/cgi-bin/tmp.txt b/www/cgi-bin/tmp.txt new file mode 100755 index 0000000..38baac9 --- /dev/null +++ b/www/cgi-bin/tmp.txt @@ -0,0 +1 @@ +{"name":"disen","pwd":"123456"}disen12345 \ No newline at end of file diff --git a/www/index.html b/www/index.html new file mode 100755 index 0000000..6ca5f1d --- /dev/null +++ b/www/index.html @@ -0,0 +1,111 @@ + + + + + + + + 主页 + + + + +
+ +
+ [登出] +
+
+ +
+ +
+ +
+
+ + + + + \ No newline at end of file diff --git a/www/login.html b/www/login.html index 6d01031..7688daf 100755 --- a/www/login.html +++ b/www/login.html @@ -10,14 +10,18 @@