解决方案 »
- PHP 如何登陆 QQ空间并且保持会话
- [求解]服务器设置为不可访问外网那是否可以使用phpmailer的SMTP发邮件呢?
- PHP和Mysql如何完成数组参数的事务?
- 校内的相册上传技术是怎么回事
- mysql出错,求教!!
- 如何让用户在下载时同时看到html网页?
- 图片显示问题
- 菜鸟问题:mysql数据库的表中字段content的值为aaaaa&bbbbb&cccccc&dddddd,我现在想要查找包括 cccccc的记录,语句怎么写?
- 如何用PHP发送HTML格式邮件?
- 请问如何将 TIMESTAMP 的值格式化输出,如:20020117113349 显示成 2002-1-17 11:43
- 为什么,父类方法会提前执行。
- PHP生成嵌套JSON
也可以 base64 编码使用
function rc4_zz($data,$pwd="") {
$key [] = "";
$box [] = "";
$cipher= "";
$pwd = str_pad($pwd, 256, chr(0)); //加上这句
$pwd_length = strlen ( $pwd );
$data_length = strlen ( $data );
for($i = 0; $i < 256; $i ++) {
$key [$i] = ord ( $pwd [$i % $pwd_length] );
$box [$i] = $i;
}
for($j = $i = 0; $i < 256; $i ++) {
$j = ($j + $box [$i] + $key [$i]) % 256;
$tmp = $box [$i];
$box [$i] = $box [$j];
$box [$j] = $tmp;
}
for($a = $j = $i = 0; $i < $data_length; $i ++) {
$a = ($a + 1) % 256;
$j = ($j + $box [$a]) % 256;
$tmp = $box [$a];
$box [$a] = $box [$j];
$box [$j] = $tmp;
$k = $box [(($box [$a] + $box [$j]) % 256)];
$cipher .= chr ( ord ( $data [$i] ) ^ $k );
}
return $cipher;
}
//加密模块
var rsa = (function($){
var publicKey
// 获取公钥
var getPubKey = function(callback){
if(publicKey) return callback();
$.post('/accounts/prelogin').always(function(json){
if(json && json.status == 'ok'){
publicKey = json.data
if(callback) callback()
}
})
} // rsa加密
var encrypt = function(txt){
if(!publicKey) return txt
var rsa = new RSA.RSAKey()
rsa.setPublic(publicKey.n, publicKey.e)
var res = rsa.encrypt(txt)
res = RSA.linebrk( RSA.hex2b64(res) )
return res
}
return {
publicKey: publicKey,
encrypt: encrypt,
getPubKey: getPubKey
}
})(jQuery);/*********************************
KP邮箱注册插件v1.0作者: wangning1
**********************************/;(function($){
$.fn.emailRegister = function(options){
options = $.extend({
formEle: $(this),
msgEle: $(this).find(".msg"),
submitUrl : $(this).attr('action'),
loginIdEle: $(this).find("input[name='loginId']"),
pwdEle: $(this).find("input[name='password']"),
repwdEle: $(this).find("input[name='repassword']"),
captchaEle: $(this).find("input[name='captcha']"),
protocal: $('#ereg-protocol'),
success: $.noop}, options);
var ERROR_MESSAGES = {
"serverError": "服务器维护中(api),请稍后再试",
"accountServerError": "服务器维护中(account),请稍后再试",
"unknownError": "服务器错误",
"clientBadParams": "手机号格式不正确",
"mobileExists": "手机号已注册或已绑定过其它账号",
"sendMsgError": "短信服务器异常,请稍后再试",
"tooManyRequests": "您今天的短信请求太多",
"tooOften": "短信请求太频繁,请稍后再试",
"invalidCode": "无效的验证码",
'captchaError' : '验证码错误',
"invalidMobile": "无效的手机号,请检查您的输入",
"emptyPassword": "密码不能为空",
"passwordTooLong": "密码太长",
"noSuchUser": "操作失败,无此用户",
"bindMobileBefore": "手机号已注册或绑定过其它账号",
"needPassword": "用户邮箱为空,需要密码",
"anNotPassword": "用户有邮箱,不能输入密码",
"sameEmailRegisteredBefore": "该邮箱已注册"
}; $('#change-code, #captcha').click(function() {
$("#captcha").attr('src', '/captcha?' + new Date().getTime())
})
function showMsg(Msg){
options.msgEle.html(Msg);
}$(this).submit(function(){
return false;
})$(this).submit(function(){
if(checkLoginId() && checkPwd() && checkProtocol()){
submit();
}
})function submit() {
var loginId = $.trim(options.loginIdEle.val());
var pwd = $.trim(options.pwdEle.val());var captcha = $.trim(options.captchaEle.val());rsa.getPubKey(function(){
var para = {
'loginId': loginId,
'password': pwd,
} if(true){
para.security = 1;
para.loginId = rsa.encrypt(para.loginId);
para.password = rsa.encrypt(para.password);
para.captcha = captcha;
}$.post(options.submitUrl, para, function(data){
if(data.status == 'ok'){
options.formEle.trigger('reset');
options.success('注册成功');
}else{
if(typeof ERROR_MESSAGES[data.status] == 'string'){
showMsg(ERROR_MESSAGES[data.status]);
}else{
showMsg('账号密码不正确,错误码:' + data.status);
}
}
}, 'json');
});
}function checkLoginId() {
var loginId = $.trim(options.loginIdEle.val());if('' === loginId) {
showMsg('邮箱地址不能为空');
return false;
}if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/i.test(loginId) && !/^1\d{10}$/i.test(loginId) ){
showMsg('账号格式不正确');
return false;
} return true;
}
//检测是否同意注册协议
function checkProtocol() {if(options.protocal.attr('checked') !== 'checked'){
showMsg('请先阅读并同意注册协议');
return false;
}else{
showMsg(' ');
return true;
}}function checkPwd() {
var pwd = $.trim(options.pwdEle.val());
var repwd = $.trim(options.repwdEle.val());if('' === pwd) {
showMsg('密码不能为空');
return false;
}if(pwd.length < 6 ){
showMsg('密码过短,不能小于6个字符');
return false;
}if(pwd.length > 32 ){
showMsg('密码过长,不能大于32个字符');
return false;
}
if('' === repwd) {
showMsg('确认密码不能为空');
return false;
}if(pwd !== repwd ) {
showMsg('两次密码不一致');
return false;
}return true;
}}
})(jQuery);