void setpassword()
{
int a = 0;
int b = 0;
int c;
Serial.println(" Enter Master Key to set password: ");
while(b < 4)
{
key = kpd.getKey();
if(key)
{
pass1[b++] = key;
Serial.println(key);
}}
if (b == 3)
{
for(c = 0; c < 4; c++)
{
pass[c] = EEPROM.read(c);
}
}
if(c == 3)
{
compareduringset();
}
if(!flag)
{
Serial.println("Master Key to set is valid");
Serial.println("Enter New password: ");
while(a < 4)
{
key = kpd.getKey();
if(key)
{
pass2[a++] = key;
Serial.println(key);
}
if(a == 3)
{
EEPROM.write(8,pass2[0]);
EEPROM.write(9,pass2[1]);
EEPROM.write(10,pass2[2]);
EEPROM.write(11,pass2[3]);
}
}
Serial.println("New Password Saved");
}
else
{
Serial.println("Master Key to set is Invalid");
call();
}
}
Code for comparing pass
and pass1[c]: Please correct me if i am wrong with the comparison logic:
[code]
void compareduringset()
{
int h;
for(h = 0; h<4; h++)
{
if(pass[h] == pass1[h])
flag = 0;
}
}
[/code]
Note that pass[] and pass1[] are character arrays.
I am saving 2 master passwords in the EEPROM through a sketch and then retrieving them using this sketch. But, my problem is whatever value I enter for my master password in this sketch(other than the actual one) it is always showing the output as Master key valid. I have tried another alternative, but in that it is displaying the output as Master key invalid, even if the entered password is correct.