Secure data entry in C ++

Last update on July 26, 2009 10:03 AM by jak58
Published by jak58

Secure data entry in C ++








Sometimes when creating a program, it is needed that additional information from the user must be enterd. In C++ information is collected, via the object :"cin". If you do not secure these entries, then your program is likely to be victim of a "buffer overflow".

IF the number of characters entered exceeds the buffer size originally planned, then the latest data overwrites other data on the stack and write false data to ESP and EBP registries.

Using get ()


You can secure these data entries in different ways. For example, using the member method "get ()" of the object "cin" can be a solution.
#include <iostream>

int main() {

char text[100];
cin.get(text, 100);  
return0;

}



This example illustrates the use of cin.get.
If the text entered exceeds the allocated size, the characters will be ignored too.

Using "getline ()"


This method works like get (), but it deletes the end buffer. To validate a text, the user must press the "enter" key, which corresponds to the character

'\n'. getline(), removing this character at the end of the buffer.

Remove go to newline without using getline ()


It is possible to delete the character at the end of buffer without using getline (). To do this, use the method "ignore ()" of the object "cin".

Ttwo parameters are used: the number of characters to ignore, and the end character.
If you write:
cin.ignore(12, '\n')

If the character '\ n' is in the first 12 characters of the string, it will be deleted.

It also allows you to filter the inputs, for example if you want to save a phone number, it will ignore all characters different from 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
Best answers for « Secure data entry in C ++ » in :
Spreadsheets - Data Entry Show Cell Content A cell of a worksheet can contain a value or be empty. The value of a cell has two essential characteristics: a type, which means the intrinsic type of the data. There are generally three types of values: numeric values, for example...
Secure your php code ShowSecure your php code Validating the data users Validate data from URL or Forms Skip displayed content of the URL It is crucial to ensure secure data from users (forms and urls etc) apart from the OS server and http server mainly...
Backup Outlook 2003 data ShowBackup Outlook 2003 data All Outlook 2003 data ( Emails, Agenda, Contacts, Tasks...) are in one file with .pst extension The file is in the following default folder: C:\Documents and Settings\Login\Local Settings\Application...
Inputs / Outputs: The streams in C ++ ShowInputs / Outputs: The streams in C ++ Open a file for reading Open a file for writing To save data after closing your programs, you must write the data into files. Here is how to proceed. To open a file, either for reading...
Download CDX ESafeFile ShowCDX ESafeFile secures your email messages, files and attachments. ESafeFile secures data with your choice of the Blowfish or AES encryption algorithms. Advantage ESafeFile does not require your recipient to install special software or download...
Protection - RAID Systems ShowPresentation of RAID Technology RAID technology (acronym for Redundant Array of Inexpensive Disks, or sometimes Redundant Array of Independent Disks) allows user to form one storage unit from several hard drives. The created unit (called a...
Data tampering attacks ShowMost web application attacks involving soliciting a website with manually entered data to generate an unexpected context. Web application parameters The HTTP protocol, a communication protocol on the web, makes it possible to convey parameters in...
Partition - Partitioning a hard drive ShowWhat is a partition? The partitioning of a hard drive occurs after the drive has been physically formatted but before it is logically formatted. It involves creating areas on the disk where data will not be mixed. It can be used, for example, to...