char* hash_password_v1( const unsigned char* b0 , int b0len
, const unsigned char* password , int psdlen)
{
unsigned char* dst = (unsigned char*)malloc(b0len + psdlen + 1);
unsigned char tmp[20];
char* res;
memset(tmp , 0 , sizeof(tmp));
memset(dst , 0 , b0len + psdlen + 1);
memcpy(dst , b0 , b0len);
memcpy(dst + b0len , password , psdlen);
SHA_CTX ctx;
SHA1_Init(&ctx);
SHA1_Update(&ctx , dst , b0len + psdlen );
SHA1_Final(tmp , &ctx);
free(dst);
res = hextostr(tmp , 20);
return res;
}
char* hash_password_v2( const char* userid , const char* passwordhex)
{
int id = atoi(userid);
char* res;
unsigned char* bid = (unsigned char*)(&id);
unsigned char ubid[4];
int bpsd_len;
unsigned char* bpsd = strtohex(passwordhex , &bpsd_len);
memcpy(ubid , bid , 4);
res = hash_password_v1(ubid , sizeof(id) , bpsd , bpsd_len);
free(bpsd);
return res;
}
char* hash_password_v4( const char* userid , const char* password)
{
const char* domain = "fetion.com.cn:";
char *res , *dst;
unsigned char* udomain = (unsigned char*)malloc(strlen(domain));
unsigned char* upassword = (unsigned char*)malloc(strlen(password));
memset(udomain , 0 , strlen(domain));
memcpy(udomain , (unsigned char*)domain , strlen(domain));
memset(upassword , 0 , strlen(password));
memcpy(upassword , (unsigned char*)password , strlen(password));
res = hash_password_v1(udomain , strlen(domain) , upassword , strlen(password));
free(udomain);
free(upassword);
if(userid == NULL || strlen(userid) == 0)
{
return res;
}
dst = hash_password_v2(userid , res);
free(res);
return dst;
}