在录制用户注册登录脚本时,常常会遇到web程序对用户密码进行加密处理。在很多时候采用的加密方式为MD5.

这时有两种处理方式:

一、所有用户采用同一密码

例如:每个用户名的密码都为e10adc3949ba59abbe56e057f20f883e

该密码即123456

二、用户采用不同的密码,调用md5加密算法进行加密。

1、首先新建一个MD5加密算法的文件:md5.h

新建一个md5.h文件,文件里面具体的算法网上都有下载,具体如下(直接将下面的算法拷贝到md5.h文件中):

#ifndef MD5_H
#define MD5_H
#ifdef __alpha
typedef unsigned int uint32;
#else
typedef unsigned long uint32;
#endif
struct MD5Context {
uint32 buf[];
uint32 bits[];
unsigned char in[];
};
extern void MD5Init();
extern void MD5Update();
extern void MD5Final();
extern void MD5Transform();
typedef struct MD5Context MD5_CTX;
#endif
#ifdef sgi
#define HIGHFIRST
#endif
#ifdef sun
#define HIGHFIRST
#endif
#ifndef HIGHFIRST
#define byteReverse(buf, len) /* Nothing */
#else
void byteReverse(buf, longs)unsigned char *buf; unsigned longs;
{
uint32 t;
do {
t = (uint32) ((unsigned) buf[] << | buf[]) << |((unsigned) buf[] << | buf[]);
*(uint32 *) buf = t;
buf += ;
} while (--longs);
}
#endif
void MD5Init(ctx)struct MD5Context *ctx;
{
ctx->buf[] = 0x67452301;
ctx->buf[] = 0xefcdab89;
ctx->buf[] = 0x98badcfe;
ctx->buf[] = 0x10325476;
ctx->bits[] = ;
ctx->bits[] = ;
}
void MD5Update(ctx, buf, len) struct MD5Context *ctx; unsigned char *buf; unsigned len;
{
uint32 t;
t = ctx->bits[];
if ((ctx->bits[] = t + ((uint32) len << )) < t)
ctx->bits[]++;
ctx->bits[] += len >> ;
t = (t >> ) & 0x3f;
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
t = - t;
if (len < t) {
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, );
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
while (len >= ) {
memcpy(ctx->in, buf, );
byteReverse(ctx->in, );
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += ;
len -= ;
}
memcpy(ctx->in, buf, len);
}
void MD5Final(digest, ctx)
unsigned char digest[]; struct MD5Context *ctx;
{
unsigned count;
unsigned char *p;
count = (ctx->bits[] >> ) & 0x3F;
p = ctx->in + count;
*p++ = 0x80;
count = - - count;
if (count < ) {
memset(p, , count);
byteReverse(ctx->in, );
MD5Transform(ctx->buf, (uint32 *) ctx->in);
memset(ctx->in, , );
} else {
memset(p, , count - );
}
byteReverse(ctx->in, );
((uint32 *) ctx->in)[] = ctx->bits[];
((uint32 *) ctx->in)[] = ctx->bits[];
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, );
memcpy(digest, ctx->buf, );
memset(ctx, , sizeof(ctx));
} #define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
#define MD5STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
void MD5Transform(buf, in)
uint32 buf[]; uint32 in[];
{
register uint32 a, b, c, d;
a = buf[];
b = buf[];
c = buf[];
d = buf[];
MD5STEP(F1, a, b, c, d, in[] + 0xd76aa478, );
MD5STEP(F1, d, a, b, c, in[] + 0xe8c7b756, );
MD5STEP(F1, c, d, a, b, in[] + 0x242070db, );
MD5STEP(F1, b, c, d, a, in[] + 0xc1bdceee, );
MD5STEP(F1, a, b, c, d, in[] + 0xf57c0faf, );
MD5STEP(F1, d, a, b, c, in[] + 0x4787c62a, );
MD5STEP(F1, c, d, a, b, in[] + 0xa8304613, );
MD5STEP(F1, b, c, d, a, in[] + 0xfd469501, );
MD5STEP(F1, a, b, c, d, in[] + 0x698098d8, );
MD5STEP(F1, d, a, b, c, in[] + 0x8b44f7af, );
MD5STEP(F1, c, d, a, b, in[] + 0xffff5bb1, );
MD5STEP(F1, b, c, d, a, in[] + 0x895cd7be, );
MD5STEP(F1, a, b, c, d, in[] + 0x6b901122, );
MD5STEP(F1, d, a, b, c, in[] + 0xfd987193, );
MD5STEP(F1, c, d, a, b, in[] + 0xa679438e, );
MD5STEP(F1, b, c, d, a, in[] + 0x49b40821, );
MD5STEP(F2, a, b, c, d, in[] + 0xf61e2562, );
MD5STEP(F2, d, a, b, c, in[] + 0xc040b340, );
MD5STEP(F2, c, d, a, b, in[] + 0x265e5a51, );
MD5STEP(F2, b, c, d, a, in[] + 0xe9b6c7aa, );
MD5STEP(F2, a, b, c, d, in[] + 0xd62f105d, );
MD5STEP(F2, d, a, b, c, in[] + 0x02441453, );
MD5STEP(F2, c, d, a, b, in[] + 0xd8a1e681, );
MD5STEP(F2, b, c, d, a, in[] + 0xe7d3fbc8, );
MD5STEP(F2, a, b, c, d, in[] + 0x21e1cde6, );
MD5STEP(F2, d, a, b, c, in[] + 0xc33707d6, );
MD5STEP(F2, c, d, a, b, in[] + 0xf4d50d87, );
MD5STEP(F2, b, c, d, a, in[] + 0x455a14ed, );
MD5STEP(F2, a, b, c, d, in[] + 0xa9e3e905, );
MD5STEP(F2, d, a, b, c, in[] + 0xfcefa3f8, );
MD5STEP(F2, c, d, a, b, in[] + 0x676f02d9, );
MD5STEP(F2, b, c, d, a, in[] + 0x8d2a4c8a, );
MD5STEP(F3, a, b, c, d, in[] + 0xfffa3942, );
MD5STEP(F3, d, a, b, c, in[] + 0x8771f681, );
MD5STEP(F3, c, d, a, b, in[] + 0x6d9d6122, );
MD5STEP(F3, b, c, d, a, in[] + 0xfde5380c, );
MD5STEP(F3, a, b, c, d, in[] + 0xa4beea44, );
MD5STEP(F3, d, a, b, c, in[] + 0x4bdecfa9, );
MD5STEP(F3, c, d, a, b, in[] + 0xf6bb4b60, );
MD5STEP(F3, b, c, d, a, in[] + 0xbebfbc70, );
MD5STEP(F3, a, b, c, d, in[] + 0x289b7ec6, );
MD5STEP(F3, d, a, b, c, in[] + 0xeaa127fa, );
MD5STEP(F3, c, d, a, b, in[] + 0xd4ef3085, );
MD5STEP(F3, b, c, d, a, in[] + 0x04881d05, );
MD5STEP(F3, a, b, c, d, in[] + 0xd9d4d039, );
MD5STEP(F3, d, a, b, c, in[] + 0xe6db99e5, );
MD5STEP(F3, c, d, a, b, in[] + 0x1fa27cf8, );
MD5STEP(F3, b, c, d, a, in[] + 0xc4ac5665, );
MD5STEP(F4, a, b, c, d, in[] + 0xf4292244, );
MD5STEP(F4, d, a, b, c, in[] + 0x432aff97, );
MD5STEP(F4, c, d, a, b, in[] + 0xab9423a7, );
MD5STEP(F4, b, c, d, a, in[] + 0xfc93a039, );
MD5STEP(F4, a, b, c, d, in[] + 0x655b59c3, );
MD5STEP(F4, d, a, b, c, in[] + 0x8f0ccc92, );
MD5STEP(F4, c, d, a, b, in[] + 0xffeff47d, );
MD5STEP(F4, b, c, d, a, in[] + 0x85845dd1, );
MD5STEP(F4, a, b, c, d, in[] + 0x6fa87e4f, );
MD5STEP(F4, d, a, b, c, in[] + 0xfe2ce6e0, );
MD5STEP(F4, c, d, a, b, in[] + 0xa3014314, );
MD5STEP(F4, b, c, d, a, in[] + 0x4e0811a1, );
MD5STEP(F4, a, b, c, d, in[] + 0xf7537e82, );
MD5STEP(F4, d, a, b, c, in[] + 0xbd3af235, );
MD5STEP(F4, c, d, a, b, in[] + 0x2ad7d2bb, );
MD5STEP(F4, b, c, d, a, in[] + 0xeb86d391, );
buf[] += a;
buf[] += b;
buf[] += c;
buf[] += d;
}
char* CMd5(const char* s)
{
struct MD5Context md5c;
unsigned char ss[];
char subStr[],resStr[];
int i;
MD5Init( &md5c );
MD5Update( &md5c, s, strlen(s) );
MD5Final( ss, &md5c );
strcpy(resStr,"");
for( i=; i<; i++ )
{
sprintf(subStr, "%02x", ss[i] );
itoa(ss[i],subStr,);
if (strlen(subStr)==) {
strcat(resStr,"");
}
strcat(resStr,subStr);
}
strcat(resStr,"\0");
return resStr;
}

2、把新建的md5.h文件,放到脚本中。放置路径为脚本存放路径。例如我的脚本login被存放在E:\LR\JTlogin下面。所以我的放置路径为:E:\LR\JTlogin\login\ (注意:一定要放置在脚本下面)

3、接下来需要在LR中导入md5.h文件。

导入方法:右键单击globals.h,选择Add Files to Script添加md5.h文件。

    

添加完成后,LR中就有该文件了。如下:

4、然后在头文件globals.h中添加引用#include "md5.h"

5、上述步骤完成后,我们现在可调用CMd5()方法进行加密。

就这样我们就加密完成了,最后要做的就是将加密的password值传给需要用到的地方就可以了。

最新文章

  1. js做灯泡明灭特效
  2. [NOIP2011] 普及组
  3. 解决Exception in thread &quot;main&quot; java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
  4. MJRefresh简单处理
  5. C#部署安装,将用户安装路径记录下写入注册表,并启动
  6. iframe获取父、子窗口的方法
  7. 微软阵营企稳的利好消息:.NET开源、Visual Studio免费
  8. Nhibernate Icreteria 分页查询
  9. sqlmap
  10. POJ2632 Crashing Robots(模拟)
  11. 229. Majority Element II求众数II
  12. Go指南练习_斐波纳契闭包
  13. idea输出目录详解
  14. 在bat中执行sql,并配置windows计划任务,并隐藏命令窗口 (转)
  15. 通向全栈之路——(4)nginx反向代理配置
  16. 7. python 字符串格式化方法(2)
  17. Delphi 简体 繁体 转换
  18. Struts2自定义标签2自定义一个按班级id查询出该班级下的学生,存放进值栈,并遍历出来。
  19. *.vue文件的template标签内使用form标签
  20. 2015-04-14——css3 @media

热门文章

  1. 使用Geomagic处理点云一般步骤
  2. python 拷贝某个文件到另一个目录下
  3. 关于vue项目报错:this relative module was not found
  4. JZOJ2368 【SDOI2011】黑白棋
  5. JZOJ P5829 HZOI 20190801 A string 线段树
  6. RN 开发工具及发布release版本
  7. Django项目:CRM(客户关系管理系统)--60--50PerfectCRM实现CRM客户报名流程学生合同URL随机码
  8. Go语言cookie的基本操作
  9. (一)SpringBoot入门【基于2.x版本】
  10. MyBatis映射器(一)--多参数传递方式