-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.h
More file actions
75 lines (71 loc) · 1.88 KB
/
Auth.h
File metadata and controls
75 lines (71 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include<Arduino.h>
#include "GlobalOptions.h"
/*
* Set according to your applications need
*/
#define EEPROM_START_ADDR 0
/*
* This value verifies that it
* is valid data starting at EEPROM_START_ADDR
* Randomly change this value when
* any if password/phone length or default values
* are changed
* MUST BE less than 256 (ie one byte)
*/
#define EEPROM_SIGNATURE 1
/*
* change these values to suite your needs
*/
#define PASSWORD_LEN 11
#define PHONE_LEN 11
#define DEFAULT_PASSWORD "KPCHSS"
#define DEFAULT_PHONE "9567665206"
/*
* This class stores the password
* of user and provides methods
* to authenticate,change password and
* reset password to a default
* value.
* Functions are provided to permanently
* store the password
* to EEPROM of the MCU.
*/
class Auth {
public:
/*
* Save the password and mobile no
* to EEPROM
*/
void storeToEEPROM();
/*
* Restores the password and mobile no from
* EEPROM to RAM
* Must be called everytime the object
* is constructed. Provided as a separate function
* for lazy loading
* returns false if the EEPROM
* doesnot contain any valid data to restore
*/
bool restoreFromEEPROM();
/*
* reset password to a default value
*/
void resetAuth();
/*
* Simply password == this->password :P
*/
bool tryAuthenticate(char password[PASSWORD_LEN]);
/*
* tryAuthenticate; if succeed:
* this->password = newPassword
* return true;
* else return false
*/
bool changePassword(char old_password[PASSWORD_LEN],char new_password[PASSWORD_LEN]);
char* getPhone();
void setPhone(char phone[]);
private:
char phone[PHONE_LEN];
char password[PASSWORD_LEN];
};