import dbm
import sys
import os
import win32con, win32api


from PyQt5.QtWidgets import (QWidget,QPushButton,QLineEdit,QLabel,
                             QVBoxLayout,QHBoxLayout,QApplication,QMessageBox)

b = os.getcwd() + '\\password\\'
name = ['知乎','QQ','学信网','email','52pj','新浪微博','交警12123',
        'google帐号','微软帐号','appleID']
class Windows(QWidget):
    def __init__(self):
        super().__init__()
        self.passCheck()
        self.resize(300, 150)
        self.setFixedSize(self.width(), self.height())#窗口禁止拉伸
        self.setWindowTitle('Jevor密码本')
        self.show()

    def passCheck(self):
        # 标签内容
        userLabel = QLabel('User:')
        userLabel.setFixedWidth(35)
        passwordLabel = QLabel('psd:')
        passwordLabel.setFixedWidth(35)
        #输入框
        self.userLineEdit = QLineEdit()
        self.userLineEdit.setPlaceholderText("请输入ID")
        self.passwordLinEdit = QLineEdit()
        self.passwordLinEdit.setPlaceholderText("请输入密码")
        self.passwordLinEdit.setEchoMode(QLineEdit.Password)#密码输入框加密

        loginButton = QPushButton('登录')
        clearButton = QPushButton('隐藏')


        h1=QHBoxLayout()
        h1.addWidget(userLabel)
        h1.addWidget(self.userLineEdit)
        h2=QHBoxLayout()
        h2.addWidget(passwordLabel)
        h2.addWidget(self.passwordLinEdit)
        mainLayout = QVBoxLayout(self)
        mainLayout.addLayout(h1)
        mainLayout.addLayout(h2)
        mainLayout.addWidget(loginButton)
        mainLayout.addWidget(clearButton)
        clearButton.clicked.connect(self.clearlot)
        loginButton.clicked.connect(self.loginslot)


    def loginslot(self):
        user = self.userLineEdit.text()
        #print(user)
        password = self.passwordLinEdit.text()
        #print(password)
        if user =='admin' and password =='jevor':
            QMessageBox.about(self, '提示', '成功')
            if not os.path.exists(b):
                os.makedirs(b)
            for file in name:
                open(b + str(file) + '.txt', "a")
            win32api.SetFileAttributes(b, win32con.FILE_ATTRIBUTE_NORMAL)


        elif user == '' or password =='':
            QMessageBox.about(self, '提示', '未输入帐号或密码')
        else:
            QMessageBox.about(self, '提示', '错误')

    def clearlot(self):
        user = self.userLineEdit.text()
        password = self.passwordLinEdit.text()
        if user == 'admin' and password == 'jevor':
            QMessageBox.about(self, '提示', '成功')
            win32api.SetFileAttributes(b, win32con.FILE_ATTRIBUTE_HIDDEN)
        elif user == '' or password == '':
            QMessageBox.about(self, '提示', '未输入帐号或密码')
        else:
            QMessageBox.about(self, '提示', '错误')









app = QApplication(sys.argv)
login = Windows()
sys.exit(app.exec_())












