瀏覽代碼

Initial public commit

Jose Ortiz 8 年之前
當前提交
f0b0d511ff
共有 6 個文件被更改,包括 213 次插入0 次删除
  1. 4
    0
      Makefile
  2. 130
    0
      README.md
  3. 79
    0
      UserValidation.cpp
  4. 二進制
      images/input_validation.png
  5. 二進制
      images/keyboard.jpg
  6. 二進制
      images/validate.jpg

+ 4
- 0
Makefile 查看文件

@@ -0,0 +1,4 @@
1
+all UserValidation:
2
+
3
+UserValidation: UserValidation.cpp
4
+		g++ UserValidation.cpp -o UV

+ 130
- 0
README.md 查看文件

@@ -0,0 +1,130 @@
1
+[English](#markdown-header-input-validation-user-registration) | [Español](#markdown-header-validacion-de-entrada-registracion-de-usuario)
2
+
3
+# Validación de entrada - Registración de usuario
4
+
5
+![keyboard.jpg](images/keyboard.jpg)
6
+![input_validation.png](images/input_validation.png)
7
+
8
+##Objetivos:
9
+
10
+1. Aprender la importancia de validar toda información entrada por un usuario
11
+2. Estar consciente de diferentes vulnerabilidades y de posibles ataques
12
+
13
+La validación de entradas es escencial en el desarrollo de aplicaciones seguras ya que es la primera línea de defensa de todas las aplicaciones.  La gran mayoría de las vulnerabilidades en aplicaciones es debido a pobre validación de las entradas. Ejemplo de vulnerabilidades explotadas por pobre validación de entradas lo son:
14
+
15
+1. Desbordamiento del Búfer 
16
+2. Cross Site Scripting
17
+3. Inyección de SQL, XML u otros lenguajes
18
+4. Recorrido de directorios
19
+5. Acceso a archivos privados
20
+
21
+Los atacantes utilizan errores en la validación de entradas para acceder a información privilegiada, para acceder a los sistemas, o para causar negación de servicios.
22
+En este laboratorio, vas a practicar a validar entradas hecha por un usuario que está creando una cuenta.
23
+
24
+Ten en mente:
25
+
26
+* **Verificar el largo:** variables son verificadas para asegurar que son del tamaño apropiado. Por ejemplo, un número de teléfono de Puerto Rico tiene 10 dígitos.
27
+* **Verificar el formato:** Verificar que la data está en un formato específico. Por ejemplo, las fechas se pueden escribir con el formato DD/MM/YYYY.
28
+* **Tipo de variable:** Vas a usar C++ para este programa; recuerda usar los métodos. Por ejemplo, puedes usar `str.length()` para obtener el largo de una cadena de caracteres.
29
+
30
+Vas a estar trabajando con el archivo `UserValidation.cpp`. Nota que la función `main` ya esta completada. Su tarea es implementar las funciones que se necesitan para validar lo que el usuario inserta como entrada.
31
+
32
+##Ejercicio 1
33
+
34
+Para esta parte vas a implementar la función `bool validateUsername(const string &username)`. Esta función recibe lo que entró el usuario como nombre de usuario.
35
+
36
+**Instrucciones**
37
+
38
+Validar que el nombre de usuario es:
39
+
40
+1. Solo tiene dígitos (usa `isdigit()` para verificar si el carácter es un dígito)
41
+2. El usuario puede insertar el nombre de usuario con guiones entre medio. Por ejemplo, 123-45-6789.
42
+3. Al terminar de limpiar la entrada, verifica que solo tenga 9 caracteres de largo.
43
+
44
+##Ejercicio 2
45
+
46
+Para esta parte vas a implementar la función `bool validatePassword(const string &password)`. Esta función recibe lo que el usuario entró como contraseña.
47
+
48
+**Instrucciones**
49
+
50
+Validar que la contraseña es:
51
+
52
+1. 8 o más caracteres de largo
53
+2. Por lo menos 1 letra mayúscula (Usa `isupper()` para verificar si es mayúscula)
54
+3. Por lo menos 1 letra minúscula (Usa `islower()` para verificar si es minúscula)
55
+4. Al menos un símbolo
56
+5. Al menos un dígito
57
+
58
+Cuando termines, abre el terminal y corre `make` para compilar. Usa `./UV` para correr el programa.
59
+
60
+
61
+---
62
+
63
+
64
+# Input validation - User registration
65
+
66
+![keyboard.jpg](images/keyboard.jpg)
67
+![input_validation.png](images/input_validation.png)
68
+
69
+##Objectives:
70
+
71
+1. Learn the importance of input validation
72
+2. Be aware of different vulnerabilities and possible attacks
73
+
74
+Input validation is esential in the development of secure applications because it is the first line of defense of every application.  The vast majority of vulnerabilities in applications is due to poor input validation of the applications.  Example of vulnerabilities explited by poor input validation are:
75
+
76
+1. Buffer overflows
77
+2. Cross Site Scripting
78
+3. SQL, XML or other languages injection
79
+4. Directory Traversal
80
+5. Access to private files
81
+
82
+The attackers use errors in input validation to gain access to priviledged information, to gain access to systems, or to cause denial of services.
83
+In this lab, you will learn to validate all input inserted by an user who is creating an account. 
84
+
85
+Keep in mind:
86
+
87
+* **Length check:** variables are checked to ensure they are the appropriate length, for example, a US telephone number has 10 digits.
88
+* **Format check:** Checks that the data is in a specified format (template), e.g., dates have to be in the format DD/MM/YYYY.
89
+* **Variable type:** You will use C++ for this program; remember the use of methods. For example, you can use `str.length()` to obtain the length of a string.
90
+
91
+You will be working with the file `UserValidation.cpp`. Note that the main function is already completed. Your task is to implement the functions that are needed to validate the user's input.
92
+
93
+##Exercise 1
94
+
95
+For this part you will need to implement the function `bool validateUsername(const string &username)`. This function receives what the user inserted as the username.
96
+
97
+**Instructions**
98
+
99
+Validate that the username is:
100
+
101
+1. Only has digits (use `isdigit()` to verify if the character is a digit)
102
+2. The user can insert the username with dashes in between. For example, 123-45-6789.
103
+3. When finished cleaning the input, verify that it only has 9 digits.
104
+
105
+ 
106
+##Exercise 2
107
+
108
+ For this part you will need to implement the function `bool validatePassword(const string &password)`. This function receives what the user inserted as the password.
109
+
110
+ **Instructions**
111
+
112
+Validate that the password is:
113
+
114
+1. 8 or more characters of length
115
+2. At least 1 uppercase letter (Use `isupper()` to verify if the character is uppercase)
116
+3. At least 1 lowercase letter (Use `islower()` to verify if the character is lowercase)
117
+4. Al least 1 symbol
118
+5. At least 1 digit
119
+
120
+After it is done, open the terminal and run `make` to compile. Use `./UV` to run the program.
121
+
122
+---
123
+
124
+##References:
125
+
126
+ [1] http://cis1.towson.edu/~cssecinj/modules/cs0/input-validation-cs0-c/
127
+
128
+ [2] http://www.mrmartincurrie.com/tag/input-validation/
129
+
130
+ [3] http://www.howtogeek.com/174952/the-20-most-important-keyboard-shortcuts-for-windows-pcs/

+ 79
- 0
UserValidation.cpp 查看文件

@@ -0,0 +1,79 @@
1
+#include <iostream>
2
+#include <string>
3
+
4
+using namespace std;
5
+
6
+/* This is a simple example to test input validation. The user must create an account with an username and password. The username must be the student number.
7
+ * This will determine if the username is of exactly 9 digits. It will also determine if the user enters a password
8
+ * with the following characteristics.
9
+ *      1. 8 or more characters of length
10
+ *      2. At least 1 upper case letter
11
+ *      3. At least 1 lower case letter
12
+ *      4. Al least 1 symbol
13
+ *      5. At least 1 digit
14
+ * The program will not finish until the user enters a correct password and then re-enters the same password.
15
+ */
16
+
17
+ //Input validation for the username
18
+bool isUsername(const string &username){
19
+	// INSERT YOUR CODE HERE
20
+
21
+	return 1 ; // CHANGE
22
+}
23
+
24
+//Input validation for the password
25
+bool isPassword(const string &password){
26
+	// INSERT YOUR CODE HERE
27
+	
28
+	return 1 ; // CHANGE
29
+}
30
+
31
+int main()
32
+{
33
+
34
+    string password, username, repassword;
35
+    bool flaguser = false, flagpass = false;
36
+    cout << "Please enter username (Student number, with or without dash): ";
37
+    cin >> username;
38
+    do{
39
+        if(isUsername(username)){
40
+            flaguser = true;
41
+            cout << "The username is correct." << endl;
42
+        }
43
+        else{
44
+            cout << "Please enter a correct username: ";
45
+            cin >> username;
46
+        }
47
+    }while(!flaguser);
48
+
49
+    cout << endl;
50
+    cout << "Please enter a password with the following conditions: " << endl;
51
+    cout << "\t1. 8 or more characters" << endl;
52
+    cout << "\t2. At least 1 upper case letter" << endl;
53
+    cout << "\t3. At least 1 digit" << endl;
54
+    cout << "\t4. At least 1 symbol" << endl << endl;
55
+    do{
56
+        cout << "Please enter password: ";
57
+        cin >> password;
58
+        if(password.length() >= 8){
59
+            if(isPassword(password)){
60
+                cout << "Please reenter the password: ";
61
+                cin >> repassword;
62
+                if(password == repassword){
63
+                    cout << "The password matched." << endl;
64
+                    flagpass = true;
65
+                }
66
+                else {
67
+                    cout << "The password did not matched." << endl;
68
+                }
69
+            }
70
+            else{
71
+                cout << "The password did not pass the conditions." << endl;
72
+            }
73
+        }
74
+    }while(!flagpass);
75
+    cout << "Congratulations, you have succesfully created an account!" << endl;
76
+
77
+    return 0;
78
+}
79
+

二進制
images/input_validation.png 查看文件


二進制
images/keyboard.jpg 查看文件


二進制
images/validate.jpg 查看文件