Use the sqlite3 C language to implement the login registration function, the database sqlite3

Source: Internet
Author: User
Tags psql sql error account security

Use the sqlite3 C language to implement the login registration function, the database sqlite3

// This code is the registration function void create_regtable () {int rc; // rc is the returned value to determine whether the function is successfully executed. rc = 0: The function is successfully executed. rc! = 0 Function execution failed sqlite3 * db; // SQLite database pointer database struct pointer sqlite3 is struct char * pFileName = "users. db "; // database file name char * zErr; rc = sqlite3_open (pFileName, & db);/* Open the database */if (rc)/* false, shut down the database */{cleardevice (); setmode (); outtextxy (170,200, "failed to open the database! "); Sleep (1000); main (); sqlite3_close (db);} char * pSQL =" create table users (id int, pwd int, primary key (id, pwd) "; rc = sqlite3_exec (db, pSQL, & zErr);/* sqlite execution interface to create a table */if (rc! = SQLITE_ OK) {if (zErr! = NULL) {cleardevice (); setmode (); outtextxy (170,200, "SQL error! "); Sleep (1000); main (); sqlite3_free (zErr);/* release the space occupied by the error message */} sqlite3_close (db);} void reg_Insert () {users a; int rc; char No_id [10] = {0, 0, 0, 0, 0, 0, 0}; char code [6] = {"12345 "}; char incode [6]; sqlite3 * db; // SQLite database pointer char * pSQL; char * zErr;/* defines the variable */char * pFileName = "users. db "; // database file name rc = sqlite3_open (pFileName, & db);/* Open the database */if (rc)/* false, close the database */{cleardevice (); setmode (); outt Extxy (170,200, "failed to open database! "); Voice_name_error (); main (); sqlite3_close (db);} InputBox (incode, 6," Verification registration number, non-instructor personnel are not allowed to register "); if (strcmp (incode, code) = 0) {InputBox (. id, 10, "enter account"); outtextxy (295,270,. id); if (strcmp (. id, No_id) = 0) {cleardevice (); setmode (); outtextxy (170,200, "the user name cannot be blank. Please register again! "); Voice_name_error (); main ();} else {InputBox (. pwd, 10, "Enter Password"); outtextxy (293,339, "*********"); Sleep (1000 ); pSQL = sqlite3_mprintf ("insert into users values ('% s',' % s')",. id,. pwd); rc = sqlite3_exec (db, pSQL, 220,200, & zErr); if (rc) // rc = 1 {cleardevice (); setmode (); outtextxy, "account registration failed! "); Voice_register_ OK (); main (); sqlite3_close (db);} else {outtextxy (220,200, rc); cleardevice (); setmode (); outtextxy (220,200, "account registration successful! "); Voice_register_ OK (); main (); sqlite3_close (db) ;}} else {cleardevice (); main ();}}

 

// This code implements account and password logon verification void Login () {users a; int rc; sqlite3 * db; // SQLite database pointer sqlite3 struct * db pointer to sqlite3 struct const char * pFileName = "users. db "; char * zErr;/* variable that defines the returned error message */rc = sqlite3_open (pFileName, & db);/* Open the database */if (rc) /* false, close the database */{cleardevice (); setmode (); settextstyle (30, 0, ""); settextcolor (RGB (0,500, 0 )); outtextxy (220,200, "failed to open database! "); Voice_No_name (); main (); sqlite3_close (db);} InputBox (. id, 10, "enter account"); outtextxy (295,270,. id); InputBox (. pwd, 10, "Enter Password"); outtextxy (293,339, "*********"); Sleep (1500 ); char * pSQL = sqlite3_mprintf ("insert into users (id, pwd) values ('% s',' % s')",. id,. pwd); // mainly obtains the rc return value for judgment. // id and pwd form the primary key of a table (joint primary key) id/pwd no one can insert duplicate rc = 1 error if reverse rc = 0 login successful // insert id different pwd insert success rc = 0 if reverse rc = 1 Login Failed // equivalent to the user name which cannot be repeated, username and The password cannot be the same, enhancing account security. Rc = sqlite3_exec (db, pSQL, NULL, NULL, & zErr );//! Rc = 1; error if (! Rc) {// delete extra data char * pSQL = sqlite3_mprintf ("delete from users where id = '% s' and pwd =' % S'",. id,. pwd); rc = sqlite3_exec (db, pSQL, NULL, NULL, & zErr); cleardevice (); setmode (); settextstyle (30, 0, ""); settextcolor (RGB (250,200, 0, 0); outtextxy (, "Logon Failed! "); Sleep (1000); cleardevice (); main ();} else // rc = 0 OK {cleardevice (); setmode (); settextstyle (30, 0, ""); settextcolor (RGB (0,500, 0); outtextxy (250,200, "Login successful, welcome to use! "); Voice_succeed (); cleardevice (); option_Menu ();} sqlite3_close (db );}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.