Zhiqim Account(前端账户管理台)是在ZhiqimManager基础上改造成用于前端注册登录的管理系统,增加组织结构和余额,开放注册组织和组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构

森中灵 最后提交于8月前 整理为组织方式和替换新的jar
ZmrPassworder.java2KB
/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_components/zhiqim_account.htm
 *
 * Zhiqim Account is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.manager;

import org.zhiqim.kernel.constants.ZhiqimConstants;
import org.zhiqim.kernel.model.codes.SHA256;
import org.zhiqim.kernel.util.Asserts;
import org.zhiqim.kernel.util.Validates;
import org.zhiqim.manager.dbo.ZmrOperator;
import org.zhiqim.orm.ORM;
import org.zhiqim.orm.dbo.Updater;

/**
 * 密码器,系统提供一个默认的SHA256的编码算法和HEX的简单加解密算法
 * 1、建议各系统编写一个子类重写该类的三个方法,并配置到zmr.passwroder中
 * 2、如果未打开保存密码功能,encrypt/decrypt可忽略
 *
 * @version v1.0.0 @author zhichenggang 2017-1-1 新建与整理
 */
public class ZmrPassworder implements ZhiqimConstants
{
    /**
     * 操作员密码不可逆编码,默认SHA256(name + code + pass + salt)
     * 
     * @param operatorCode      操作员账号
     * @param operatorPass      操作员密码
     * @param operatorPassSalt  操作员密码盐值
     */
    public static String encode(String operatorCode, String operatorPass, String operatorPassSalt)
    {
        try
        {
            ZmrOperator item = ORM.table().item(ZmrOperator.class, operatorCode);
            if (item == null)
                return SHA256.encodeUTF8(Z_NAME + operatorCode + operatorPass + operatorPassSalt);
            
            if (Validates.isEmpty(item.getOperatorParam()))
                return SHA256.encodeUTF8(Z_NAME + operatorCode + operatorPass + operatorPassSalt);
            
            String operatorPassSha = SHA256.encodeUTF8(item.getOperatorParam() + operatorPass + operatorPassSalt);
            if (operatorPassSha.equals(item.getOperatorPass()))
            {//有操作员参数的,且密码正确的重写密码
                Updater updater = new Updater("operatorCode", operatorCode);
                updater.addField("operatorPass", SHA256.encodeUTF8(Z_NAME + operatorCode + operatorPass + operatorPassSalt));
                updater.addField("operatorPassSalt", operatorPassSalt);
                updater.addField("operatorParam", null);
                ORM.table().update(ZmrOperator.class, updater);
            }
            
            return operatorPassSha;
        }
        catch (Exception e)
        {
            throw Asserts.exception("系统异常,请与管理员联系");
        }
    }
}