Search in sources :

Example 1 with UnknownInternalException

use of com.duan.blogos.exception.internal.UnknownInternalException in project BlogSystem by DuanJiaNing.

the class BloggerAccountServiceImpl method updateAccountPassword.

@Override
public boolean updateAccountPassword(int bloggerId, String oldPassword, String newPassword) {
    String oldSha;
    String newSha;
    try {
        oldSha = new BigInteger(StringUtils.toSha(oldPassword)).toString();
        newSha = new BigInteger(StringUtils.toSha(newPassword)).toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new UnknownInternalException(e);
    }
    BloggerAccount account = accountDao.getAccountById(bloggerId);
    String oriSha = account.getPassword();
    // 旧密码正确,同时与新密码相同(并没有修改)
    if (!oriSha.equals(oldSha) || oldSha.equals(newSha))
        return false;
    BloggerAccount a = new BloggerAccount();
    a.setId(bloggerId);
    a.setPassword(newSha);
    int effect = accountDao.update(a);
    if (effect <= 0)
        return false;
    return true;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) UnknownInternalException(com.duan.blogos.exception.internal.UnknownInternalException) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with UnknownInternalException

use of com.duan.blogos.exception.internal.UnknownInternalException in project BlogSystem by DuanJiaNing.

the class BloggerAccountServiceImpl method insertAccount.

@Override
public int insertAccount(String userName, String password) {
    String shaPwd;
    try {
        // 将密码通过sha的方式保存
        shaPwd = new BigInteger(StringUtils.toSha(password)).toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new UnknownInternalException(e);
    }
    BloggerAccount account = new BloggerAccount();
    account.setUsername(userName);
    account.setPassword(shaPwd);
    int effect = accountDao.insert(account);
    if (effect <= 0)
        return -1;
    int bloggerId = account.getId();
    // 生成博主设置数据
    BloggerSetting setting = new BloggerSetting();
    setting.setBloggerId(bloggerId);
    settingDao.insert(setting);
    return bloggerId;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) UnknownInternalException(com.duan.blogos.exception.internal.UnknownInternalException) BloggerSetting(com.duan.blogos.entity.blogger.BloggerSetting) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)2 UnknownInternalException (com.duan.blogos.exception.internal.UnknownInternalException)2 BigInteger (java.math.BigInteger)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)1