账号隐私保护

该代码段提供了一个AccountPrivacyUtils类,用于账号隐私保护。它根据账号类型(邮箱或电话)来隐藏部分信息。对于邮箱,它隐藏@之前的字符;对于电话,隐藏-后的数字。使用了LettinLoginWayConfig检查登录方式,并用hideString方法对特定部分进行星号(*)替换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 账号隐私保护
package cn.lettin.common.utils;

import cn.lettin.common.config.LettinLoginWayConfig;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description :  账号隐私保护
 * @Author :  ZhangYunXin
 * @CreateDate :  2020/7/24 15:10
 * @UpdateUser :  ZhangYunXin
 * @UpdateDate :  2020/7/24 15:10
 * @UpdateRemark :  新建
 */
public class AccountPrivacyUtils {

    /**
     * 账号隐私保护
     *
     * @param account
     * @return
     */
    public static String hideAccount(String account) {
        if (StringUtils.isBlank(account)) {
            return account;
        }
        LettinLoginWayConfig way = LettinLoginWayConfig.checkLoginWay(account);
        int index;
        switch (way) {
            case MAIL:
                index = account.indexOf("@");
                return hideString(account.substring(0, index)) + account.substring(index);
            case PHONE:
                index = account.indexOf("-");
                return /*account.substring(0, index + 1) + */hideString(account.substring(index + 1));
            default:
                return account;
        }
    }

    /**
     * 隐藏字符串
     *
     * @param sub
     * @return
     */
    public static String hideString(String sub) {
        int a, b, m;
        a = sub.length() / 3;
        m = sub.length() % 3;
        if (m == 2) {
            b = a + 1;
        } else {
            b = a;
        }
        StringBuilder builder = new StringBuilder();
        builder.append(sub, 0, a);
        for (int i = b; i > 0; i--) {
            builder.append("*");
        }
        builder.append(sub.substring(a + b));
        return builder.toString();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值