password提示错误。

password提示错误。

http://img1.sycdn.imooc.com//climg/5d4552580001f95504480258.jpg

class UserDao:
   def login(self,username,password):
       try:
           con=pool.get_connection()
           cursor=con.cursor()
           sql="select count(*) from t_user where username=%s and " \
               "AES_DECRYPT(UNHEX(password),'helloworld')=%s"
           cursor.execute(sql,(username,password))
           count=cursor.fetchone()[0]
           return True if count==1 else False
       except Exception as e:
           print(e)
       finally:
           if "con" in dir():
               con.close()


这个直接无法进入下一层。请老师看看

正在回答

登陆购买课程后可参与讨论,去登陆

5回答

同学,你好。同学插入数据加密时使用的是"Helloworld",但在解密时使用的是"helloworld"。加密与解密时是要相对应的。

http://img1.sycdn.imooc.com//climg/5d47fe4f0001e65f12800206.jpg

http://img1.sycdn.imooc.com//climg/5d47fe7800017ee204850216.jpg

提问者 qq_阳光_134 2019-08-05 17:36:48

http://img1.sycdn.imooc.com//climg/5d47f64d000166bd06430421.jpg

http://img1.sycdn.imooc.com//climg/5d47f6b000013d6113010539.jpg

老师,我删表后重新建表,依然提示不能登录,账号密码都没错。这个歌到底是哪里出了

http://img1.sycdn.imooc.com//climg/5d47f856000166bd06430421.jpg

http://img1.sycdn.imooc.com//climg/5d47f856000199e713440586.jpg

http://img1.sycdn.imooc.com//climg/5d47f856000128ff08670457.jpg

老师按你的方法我重新删表建表,加密的和未加密的都试过了,还是无法登录,请问这个是哪里出了问题啊?

提问者 qq_阳光_134 2019-08-04 17:49:09

老师再看看app这个吧,看看我是哪里打错了啊

import time

from colorama import Fore,Style
from getpass import getpass
from service.user_service import UserService
from service.news_service import NewsService
import os
import sys
__user_service=UserService()
__news_service=NewsService

while True:
   os.system("cls")
   print(Fore.LIGHTBLUE_EX,"\n\t===================")
   print(Fore.LIGHTBLUE_EX, "\n\t欢迎使用新闻管理系统")
   print(Fore.LIGHTBLUE_EX, "\n\t===================")
   print(Fore.LIGHTGREEN_EX,"\n\t1.登录系统")
   print(Fore.LIGHTGREEN_EX,"\n\t2.退出系统")
   print(Style.RESET_ALL)
   opt=input("\n\t输入操作编号:")
   if opt=="1":
       username=input("\n\t用户名:")
       password=getpass("\n\t密码:")
       result=__user_service.login(username,password)
       #登陆成功
       if result==True:
           #查询角色
           role=__user_service.search_user_role(username)
           os.system("cls")#清空屏幕
           while True:
               if role=="新闻编辑":
                   print("test")
               elif role=="管理员":
                   print(Fore.LIGHTGREEN_EX,"\n\t1.新闻管理")
                   print(Fore.LIGHTGREEN_EX, "\n\t2.用户管理")
                   print(Fore.LIGHTRED_EX, "\n\tback.退出登录")
                   print(Fore.LIGHTRED_EX, "\n\texit.退出系统")
                   print(Style.RESET_ALL)
                   opt = input("\n\t输入操作编号:")
                   if opt=="1":
                       while True:
                           page=1
                           os.system("cls")
                           print(Fore.LIGHTGREEN_EX, "\n\t1.审批新闻")
                           print(Fore.LIGHTGREEN_EX, "\n\t2.删除新闻")
                           print(Fore.LIGHTRED_EX, "\n\tback.返回上一层")
                           print(Style.RESET_ALL)
                           opt = input("\n\t输入操作编号:")
                           if opt=="1":
                               page=1
                               while True:
                                   os.system("cls")
                                   count_page=__news_service.search_unreview_count_page()
                                   result=__news_service.search_unreview_list(page)
                                   for index in range (len(result)):
                                       one=result[index]
                                       print(Fore.LIGHTBLUE_EX, "\n\t%d\t%s\t%s\t%s"%(index+1,one[1],one[2],one[3]))
                                   print(Fore.LIGHTBLUE_EX, "\n\t--------------------")
                                   print(Fore.LIGHTBLUE_EX, "\n\t%d/%d"%(page,count_page))
                                   print(Fore.LIGHTBLUE_EX, "\n\t--------------------")
                                   print(Fore.LIGHTRED_EX, "\n\tback.返回上一层")
                                   print(Fore.LIGHTRED_EX, "\n\tprev.上一页")
                                   print(Fore.LIGHTRED_EX, "\n\tnext.下一页")
                                   print(Style.RESET_ALL)
                                   opt = input("\n\t输入操作编号:")
                   elif opt=="back":
                       break
                   elif opt=="exit":
                       sys.exit(0)
           else:
               print("\n\t登录失败(3秒自动返回)")
               time.sleep(3)
       elif opt=="2":
           sys.exit(0)

  • 同学,你好。代码我这测试是没有问题的,同学在user_dao.py文件中添加打印username和password代码后,运行app.py文件看打印出来的是否与数据库中的一致。同学可以去掉sql语句中的加密和解密,在数据库t_user表中手动添加一条不加密的数据后再进行测试,看是否可以正常登录。另,同学t_user表中的数据是否是执行sql语句加密存进去的。
    2019-08-04 18:28:26
提问者 qq_阳光_134 2019-08-04 16:49:06


http://img1.sycdn.imooc.com//climg/5d469bd80001c54606800103.jpg

http://img1.sycdn.imooc.com//climg/5d469bd8000149dd09800241.jpg

加上print语句也没显示错误,不知道是哪里出错了,就是无法进入下一层。

  • 提问者 qq_阳光_134 #1
    而且username,password打印不出来
    2019-08-04 16:49:48
时间, 2019-08-04 11:22:59

同学,你好。

1、同学可以在程序中打印下username和password的值,是否与数据库中的一致

2、数据库中的password是否进行了加密,若没有,sql语句则不需要使用AES_DECRYPT
( )解密。

http://img1.sycdn.imooc.com//climg/5d464ddc0001d43809650418.jpg

如果我的回答解决了您的疑惑,请采纳!祝学习愉快~~~~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师