api.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import base64
  2. import hashlib
  3. from flask import Flask, request
  4. #初始化一个实例
  5. app = Flask(__name__)
  6. #MD5加密
  7. def md5(args):
  8. return hashlib.md5(str(args).encode('utf-8')).hexdigest()
  9. #Base64加密
  10. def bs64(args):
  11. return base64.b64encode(str(args).encode("utf-8")).decode(encoding ="utf-8")
  12. #模拟带参数的请求(md5加密的接口)
  13. @app.route('/md5login',methods=['GET','POST'])
  14. def md5login():
  15. username = request.values.get("username")
  16. password = request.values.get("password")
  17. print(username,password)
  18. if username == md5("admin").upper() and password == md5("123").upper():
  19. return {"message": "success"}
  20. else:
  21. return {"message": "fail"}
  22. #模拟带参数的请求(base64加密的接口)
  23. @app.route('/base64login',methods=['GET','POST'])
  24. def base64login():
  25. username = request.values.get("username")
  26. password = request.values.get("password")
  27. print(username, password)
  28. print(bs64("admin").upper(),bs64("123").upper())
  29. print(username==bs64("admin").upper() and password==bs64("123").upper())
  30. if username==bs64("admin").upper() and password==bs64("123").upper():
  31. return "success"
  32. else:
  33. return "fail"
  34. if __name__ == '__main__':
  35. app.run()