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;
}
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;
}
Aggregations