写点什么

【架构师训练营】第 11 周作业

用户头像
花生无翼
关注
发布于: 2020 年 08 月 26 日

作业一:

1.导致系统不可用的原因有哪些?保障系统稳定高可用的方案有哪些?请分别列举并简述。

答:

导致系统不可用的原因主要有:

  • 硬件故障

  • 软件Bug

  • 系统发布

  • 并发压力

  • 网络攻击/故障

  • 外部灾害

保障系统稳定高可用的方案有:

  • 解耦



  • 隔离



  • 异步



  • 备份(冗余)



  • Failover(失效转移)



  • 幂等



  • 事务补偿



  • 重试



  • 熔断



  • 限流



  • 降级



  • 异地多活



2.请用你熟悉的编程语言写一个用户密码验证函数,Boolean checkPW(String 用户 ID,String 密码明文,String 密码密文)返回密码是否正确 boolean 值,密码加密算法使用你认为合适的加密算法。

package com.ssm.simple.demo.algorithm;
import org.apache.commons.codec.binary.Hex;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* 验证用户密码
*
* @Author peanutnowing
* @Date 2020/8/26
*/
public class CheckPWDemo {
/**
* 密码验证
* @param userId
* @param password
* @param encodedPassword
* @return
* @throws NoSuchAlgorithmException
*/
public static Boolean checkPW(String userId, String password, String encodedPassword) throws NoSuchAlgorithmException {
String encryptedStr = encodeBySHA256(userId+password);
return encodedPassword.equals(encryptedStr);
}
/**
* 加密
* @param str
* @return
* @throws NoSuchAlgorithmException
*/
private static String encodeBySHA256(String str) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
byte[] digestBytes = messageDigest.digest(str.getBytes());
String digestStr = Hex.encodeHexString(digestBytes);
return digestStr;
}
public static void main(String[] args) throws NoSuchAlgorithmException {
String userId = "10001";
String pwd = "asdf1234";
System.out.println(encodeBySHA256(userId+pwd));
Boolean result = checkPW(userId, pwd, encodeBySHA256(userId+pwd));
System.out.printf("result:"+ result);
}
}



用户头像

花生无翼

关注

日拱一卒,想到做到 2017.10.29 加入

还未添加个人简介

评论

发布
暂无评论
【架构师训练营】第 11 周作业