Go to the documentation of this file.00001
00006 #include<my_lib/login.hh>
00007
00008 namespace my_lib {
00009
00010 struct login_impl{
00011 private:
00012 const char * l;
00013 unsigned long long hash;
00014
00015 static unsigned long long get_hash(const char* s){
00016 unsigned long long l=0;
00017 char * c=(char*)&l;
00018 for(;*s!=0;s++)
00019 for(int i=0;i<sizeof(l);i++)
00020 c[i]^=(*s>>i)|(*s<<(8-i));
00021 return l;
00022 }
00023
00024 login_impl(const char* login, const char* passwd) :
00025 l(login), hash(get_hash(passwd)) {}
00026 const char* login(){
00027 return l;
00028 }
00029 void chg_passwd(const char* passwd){
00030 hash=get_hash(passwd);
00031 }
00032 unsigned long long get_passwd_hash(){
00033 return hash;
00034 }
00035
00036 friend struct login_t;
00037 };
00038
00039 login_t::login_t(const char* login, const char* passwd):
00040 implementation(new login_impl(login,passwd)) {}
00041 const char* login_t::login(){
00042 return implementation->login();
00043 }
00044 void login_t::chg_passwd(const char* passwd){
00045 implementation->chg_passwd(passwd);
00046 }
00047 unsigned long long login_t::get_hash(const char* s){
00048 return login_impl::get_hash(s);
00049 }
00050 unsigned long long login_t::get_passwd_hash(){
00051 return implementation->get_passwd_hash();
00052 }
00053
00054 }