Browse code

Passwortmanager Arduino erweitert

Gerät kann mit 2 verschieden Transponder 2 Kanäle Passworte anzeigen.
Kanal 1 hat 4 Passworte umschaltbar mit Taster Rückmeldung über LED .
Kanal 2 hat 1Passwort
Wenn ein Transponder erkannt ist, wird auch mit LED gemeldet

Stefan Höhn authored on24/10/2017 17:20:15 • GitHub committed on24/10/2017 17:20:15
Showing1 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,281 @@
1
+#include <EEPROM.h>
2
+
3
+const int EEPROM_MIN_ADDR = 0;
4
+const int EEPROM_MAX_ADDR = 511;
5
+const int BUFSIZE = 15;
6
+
7
+//-------------pw2--------------
8
+#include <Keyboard.h>
9
+
10
+int i;
11
+int z = 0;
12
+int key[5];
13
+String keyvalue;
14
+int bytes_from_RFID = 5;
15
+String Password_from_eeprom;
16
+
17
+// Eingänge
18
+int Taster = 2;
19
+
20
+//Ausgänge
21
+int LEDboard = 13;
22
+int LEDtaster = 12;
23
+int LED1 = 11;
24
+int LED2 = 10;
25
+int LED3 = 9;
26
+
27
+//allg, Variablen
28
+
29
+char buf[BUFSIZE];
30
+char buf1[BUFSIZE];
31
+String myString;
32
+String myString1 = "";
33
+char myStringChar[BUFSIZE];
34
+char myStringChar1[BUFSIZE];
35
+//boolean passwort_eingabe = false;
36
+boolean endlos = false;
37
+unsigned long start = millis();
38
+char ch = "";
39
+
40
+//zaehler LED
41
+
42
+int buttonState = 0;
43
+int counter = 0;
44
+int buttonStateHIGH = 0;
45
+
46
+//--------------Funktionen-----------------------
47
+
48
+
49
+boolean eeprom_is_addr_ok(int addr) {
50
+  return ((addr >= EEPROM_MIN_ADDR) && (addr <= EEPROM_MAX_ADDR));
51
+}
52
+//----------------------
53
+boolean eeprom_write_bytes(int startAddr, const byte* array, int numBytes) {
54
+  // counter
55
+  int i;
56
+  if (!eeprom_is_addr_ok(startAddr) || !eeprom_is_addr_ok(startAddr + numBytes)) {
57
+    return false;
58
+  }
59
+  for (i = 0; i < numBytes; i++) {
60
+    EEPROM.write(startAddr + i, array[i]);
61
+  }
62
+  return true;
63
+}
64
+//-----------------------------
65
+boolean eeprom_write_string(int addr, const char* string) {
66
+
67
+  int numBytes; // actual number of bytes to be written
68
+
69
+  numBytes = strlen(string) + 1;
70
+  return eeprom_write_bytes(addr, (const byte*)string, numBytes);
71
+}
72
+//------------------------------
73
+boolean eeprom_read_string(int addr, char* buffer, int bufSize) {
74
+  byte ch; // byte read from eeprom
75
+  int bytesRead; // number of bytes read so far
76
+  if (!eeprom_is_addr_ok(addr)) { // check start address
77
+    return false;
78
+  }
79
+
80
+  if (bufSize == 0) { // how can we store bytes in an empty buffer ?
81
+    return false;
82
+  }
83
+
84
+  if (bufSize == 1) {
85
+    buffer[0] = 0;
86
+    return true;
87
+  }
88
+  bytesRead = 0; // initialize byte counter
89
+  ch = EEPROM.read(addr + bytesRead); // read next byte from eeprom
90
+  buffer[bytesRead] = ch; // store it into the user buffer
91
+  bytesRead++; // increment byte counter
92
+
93
+  while ( (ch != 0x00) && (bytesRead < bufSize) && ((addr + bytesRead) <= EEPROM_MAX_ADDR) ) {
94
+    // if no stop condition is met, read the next byte from eeprom
95
+    ch = EEPROM.read(addr + bytesRead);
96
+    buffer[bytesRead] = ch; // store it into the user buffer
97
+    bytesRead++; // increment byte counter
98
+  }
99
+  // make sure the user buffer has a string terminator, (0x00) as its last byte
100
+  if ((ch != 0x00) && (bytesRead >= 1)) {
101
+    buffer[bytesRead - 1] = 0;
102
+  }
103
+  return true;
104
+}
105
+
106
+boolean passwort_eingabe()
107
+{
108
+
109
+  //in 30 Sekunden sollte eine Verbindung aufgebaut sein
110
+  //wenn nicht, dann Betrieb mit Netzteil
111
+  //       delay (30000);
112
+  // while( endlos == false)
113
+
114
+  myString1.reserve(16);
115
+
116
+
117
+  while (millis() - start <= 30000)
118
+  {
119
+
120
+    if ( Serial.available())
121
+    {
122
+
123
+      ch = Serial.read();
124
+
125
+      myString1 = (myString1 + ch);
126
+      //---------------------------Warum dieser delay?---Keine Ahnung---------------
127
+      delay(10);
128
+    }
129
+    if (ch == 10)
130
+    {
131
+      if (myString1 != "")
132
+      {
133
+
134
+        myString1.toCharArray(myStringChar1, BUFSIZE); //convert string to char array
135
+        strcpy(buf, myStringChar1);
136
+        eeprom_write_string(0, buf);
137
+        break;
138
+
139
+      }
140
+    }
141
+  }
142
+  return true ;
143
+}
144
+
145
+
146
+void setup() {
147
+
148
+  pinMode(Taster, INPUT_PULLUP);
149
+
150
+  pinMode(LEDboard, OUTPUT);
151
+  pinMode(LEDtaster, OUTPUT);
152
+  pinMode(LED1, OUTPUT);
153
+  pinMode(LED2, OUTPUT);
154
+  pinMode(LED3, OUTPUT);
155
+
156
+
157
+
158
+  //------------------PW2---------------------
159
+  Serial1.begin(9600); // start serial to RFID reader
160
+  Keyboard.begin();
161
+  //-----------------------------------------
162
+
163
+  Serial.begin(9600);
164
+
165
+  passwort_eingabe ();
166
+  //--------------------------------------
167
+
168
+  eeprom_read_string(0, buf, BUFSIZE);
169
+  Password_from_eeprom = buf;
170
+
171
+}
172
+
173
+void loop() {
174
+
175
+  int wertTaster = digitalRead(Taster);
176
+
177
+  if (wertTaster == HIGH) {
178
+    digitalWrite(LEDboard, LOW);
179
+    //digitalWrite(LED1,HIGH);
180
+    //digitalWrite(LED2,HIGH);
181
+    //digitalWrite(LED3,HIGH);
182
+    //digitalWrite(LEDtaster,HIGH);
183
+
184
+  } else {
185
+    digitalWrite(LEDboard, HIGH);
186
+  }
187
+
188
+
189
+
190
+
191
+
192
+
193
+  buttonState = digitalRead(Taster);
194
+  if (buttonState == HIGH)
195
+  {
196
+    buttonStateHIGH = 1;
197
+
198
+  }
199
+  if (buttonState == LOW && buttonStateHIGH == 1)
200
+  {
201
+    digitalWrite(9, LOW);
202
+    digitalWrite(10, LOW);
203
+    digitalWrite(11, LOW);
204
+    counter++;
205
+    buttonStateHIGH = 0;
206
+  }
207
+  digitalWrite(counter + 7, HIGH);
208
+  if (counter == 4)
209
+  {
210
+    counter = 0;
211
+
212
+  }
213
+
214
+
215
+
216
+  //-------------PW2-------------------
217
+  if (Serial1.available() > 0)
218
+  {
219
+    i = Serial1.read();
220
+    z ++;
221
+    // -------------6 = 5+1(bytes)
222
+    if (z < (bytes_from_RFID + 1) )
223
+    {
224
+      Serial.print(i, DEC);
225
+      Serial.print(" ");
226
+      key[z] = i;
227
+      // -----------------5 bytes from RFID
228
+      if (z == bytes_from_RFID)
229
+      {
230
+        Serial.println();
231
+        Serial1.end();
232
+
233
+        keyvalue = (key[1] );
234
+        keyvalue = (keyvalue + key[2]);
235
+        keyvalue = (keyvalue + key[3]);
236
+        keyvalue = (keyvalue + key[4]);
237
+        keyvalue = (keyvalue + key[5]);
238
+
239
+        if (keyvalue == "1173154251101")
240
+          Keyboard.print(Password_from_eeprom);
241
+        else if (keyvalue == "12409413828")
242
+        {
243
+          digitalWrite(12, HIGH);
244
+
245
+          //------- \n after password means Newline or ENTER
246
+          if (counter == 0)
247
+          {
248
+            Keyboard.print("Passwort 2\n");
249
+          }
250
+          else if (counter == 1)
251
+          {
252
+            Keyboard.print("Passwort 1\n");
253
+           // Keyboard.print(Password_from_eeprom);
254
+          }
255
+
256
+
257
+          else if (counter == 2)
258
+          {
259
+            Keyboard.print("Passwort 3\n");
260
+          }
261
+
262
+
263
+          else if (counter == 3)
264
+          {
265
+            Keyboard.print("Passwort 4\n");
266
+          }
267
+
268
+        }
269
+        // -----------------5 Seconds lock
270
+        delay(5000);
271
+        digitalWrite(12, LOW);
272
+        //--------------------Thats not nice but it works.
273
+        Serial1.begin(9600);
274
+
275
+        z = 0;
276
+      }
277
+    }
278
+  }
279
+}
280
+
281
+