Qt implements Client/Server login verification | MD5 encryption is used for data transmission

Source: Internet
Author: User

Two modules are required: client and server. That is, the client sends data to the remote server segment for verification to implement simple authentication. At the same time, the client sends data to the server segment through MD5 encryption before transmission.

 

Development Environment and tools

Development operating system: Windows 8 Enterprise 32-bit

Development Platform: Based on the qt5.0.1 framework

Integrated development tool: qtcreater 2.6.2

Choose Database: mysql-6.0.11-alpha-win32 free installation Edition

 

Database Design

Because this experiment only implements a simple user login verification function, it only uses a simple user data table. Therefore, the SQL statement created for the database is as follows:

 

 

Create Database: Create Database liyangdefault Character Set utf8 collate tables; create user ly_user table: Create Table ly_user (ID int primary keyauto_increment, passwd varchar (50) notnull, email varchar (50) notnull) default charset utf8; insert Default User: insert into ly_user values (null, "2010012840", "solome@outlook.com"); Note: login verification using email/passwd, unnecessary redundant data such as user names.

Database Implementation 1 is shown.

Figure 1 Database Operation implementation

 

Server implementation

First, implement a simple server to capture the qtcpsocket data packets sent by the client. The C/S applications implemented by the TCP protocol mainly use the qtcpsocket and qtcpserver core classes on the server side.

Because TCP is a network data connection between end-to-end, the connection between processes is implemented through the IP address and the corresponding port number to prevent other applications from occupying the port number, the port number is customized on the server. Because the client must know the port currently occupied by the server to connect to the server segment ).

The design 2 of the server console interface is shown in.

Figure 2 server console Design

Because the data packet is transmitted in MD5 ciphertext, it is impossible to obtain the decrypted plaintext when the data is transmitted to the server segment. How can I read the database information for verification? I used MD5 encryption while traversing the database information, and compared and verified the ciphertext. This has the advantage that SQL injection and other similar attacks will not occur; the disadvantage is also obvious, because it is necessary to traverse the database for query operations, but the database capacity is very large, it will waste a lot of time.

When using the QT technical framework for MySQL database operations, you still encounter the problem that the MySQL driver is not available. The solution is to download the source code of MySQL and QT 5.0.1 and recompile it by yourself. Although the function interfaces provided by MySQL can be directly used, this implementation does not make it easy to use the encapsulated class library in QT, which makes the server implementation not bloated.

 

Client Login implementation

It is easier to implement the client than the server. The client logon page is shown in figure 3.

Figure 3 client User Logon

Figure 4 logon Verification Successful

Figure 5 logon Verification Failed

 

The client directly uses qtcpsocket to connect to the remote server. the MD5 encryption operation directly uses the qcryptographichash class in the QT framework and directly uses qcryptographichash (qcryptographichash: MD5 ); to implement MD5 encryption (the same way on the server side ). The logon verification succeeds and fails. A dialog box is displayed, showing the result 4 and 5, respectively.

It supports simultaneous verification by multiple clients. Not one-to-one connection transmission, but multiple-to-one connection transmission. You can open multiple clients for Logon verification.

 

Use of source code

Only installing the QT environment is not enough, the necessary operations are as follows: source code: http://www.oschina.net/code/snippet_126633_21269

① Install the full version of MySQL database and copy the libmysql. dll file under the/bin/installation directory to the System32 directory;

② QT 5.0.1 does not have a MySQL operation-related driver installed by default. Therefore, qsqldatabase and other related MySQL database operation classes cannot be used. DLL and qsqlmysqld. copy the DLL Dynamic Link Library to the QT installation directory \ 5.0.1 \ mingw47_32 \ plugins \ sqldrivers.

③ Due to network programming, add the network field to the client and server program. Pro files, and add the SQL field to the server. Pro file, such as QT + = coreguinetwork.

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.