Common stuff for all my devices' web server pages: css, login, log, ipv4, ipv6, firmware update, clock, reset info etc.
Dependents: oldheating gps motorhome heating
web-login-password.c
00001 #include <stdbool.h> 00002 #include <stdint.h> 00003 00004 #include "http.h" 00005 00006 #define GPREG2 (*((volatile unsigned *) 0x4002404C)) 00007 00008 static uint32_t hash; 00009 static bool hashIsSet = false; 00010 00011 void WebLoginPasswordRestore() 00012 { 00013 hash = GPREG2; 00014 hashIsSet = true; 00015 } 00016 00017 void WebLoginPasswordReset() 00018 { 00019 GPREG2 = 0; 00020 hashIsSet = false; 00021 } 00022 uint32_t hasher(char *p) //Jenkins 'one at a time' hash 00023 { 00024 uint32_t h = 0; 00025 00026 while (*p) 00027 { 00028 h += *p; 00029 h += (h << 10); 00030 h ^= (h >> 6); 00031 p++; 00032 } 00033 h += (h << 3); 00034 h ^= (h >> 11); 00035 h += (h << 15); 00036 00037 return h; 00038 } 00039 bool WebLoginPasswordIsSet() 00040 { 00041 return hashIsSet; 00042 } 00043 void WebLoginPasswordSet(char* password) 00044 { 00045 if (!password) return; 00046 if (!*password) return; 00047 hash = hasher(password); 00048 GPREG2 = hash; 00049 hashIsSet = true; 00050 } 00051 bool WebLoginPasswordMatches(char* password) 00052 { 00053 if (!hashIsSet) return false; 00054 if (!password) return false; 00055 if (!*password) return false; 00056 return hash == hasher(password); 00057 }
Generated on Wed Jul 13 2022 14:19:59 by 1.7.2