1stPK Posted November 17 Share Posted November 17 expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; File lưu thông tin người dùng Global $sFilePath = @ScriptDir & "\users.ini" ; Tạo giao diện chính GUICreate("Đăng nhập", 300, 150) $lblUsernameText = GUICtrlCreateLabel("Tên đăng nhập:", 10, 10, 100, 20) $inputUsername = GUICtrlCreateInput("", 120, 10, 150, 20) $lblPasswordText = GUICtrlCreateLabel("Mật khẩu:", 10, 40, 100, 20) $inputPassword = GUICtrlCreateInput("", 120, 40, 150, 20, $ES_PASSWORD) $btnLogin = GUICtrlCreateButton("Đăng nhập", 10, 80, 130, 30) $btnRegister = GUICtrlCreateButton("Đăng ký", 150, 80, 130, 30) $lblStatus = GUICtrlCreateLabel("", 10, 120, 270, 20) GUISetState(@SW_SHOW) ; Label ID đăng nhập và nút đăng xuất $lblUserID = GUICtrlCreateLabel("", 50, 50, 270, 20) $btnLogout = GUICtrlCreateButton("Đăng xuất", 100, 100, 100, 30) GUICtrlSetState($btnLogout, $GUI_HIDE) ; Ẩn nút đăng xuất GUICtrlSetState($lblUserID, $GUI_HIDE) ; Ẩn label "ID đăng nhập" ; Gán phím Enter cho nút đăng nhập HotKeySet("{ENTER}", "Login") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnRegister ShowRegisterGUI() Case $btnLogin Login() Case $btnLogout Logout() EndSwitch WEnd ; Hàm hiển thị giao diện Đăng ký Func ShowRegisterGUI() ; Xóa các thông báo lỗi cũ nếu có GUICtrlSetData($lblStatus, "") ; Tạo giao diện đăng ký Local $hRegisterGUI = GUICreate("Đăng ký tài khoản", 350, 300) GUICtrlCreateLabel("ID:", 10, 10, 100, 20) Local $inputID = GUICtrlCreateInput("", 120, 10, 200, 20) GUICtrlCreateLabel("Mật khẩu:", 10, 40, 100, 20) Local $inputPass = GUICtrlCreateInput("", 120, 40, 200, 20, $ES_PASSWORD) GUICtrlCreateLabel("Email:", 10, 70, 100, 20) Local $inputEmail = GUICtrlCreateInput("", 120, 70, 200, 20) GUICtrlCreateLabel("Số điện thoại:", 10, 100, 100, 20) Local $inputPhone = GUICtrlCreateInput("", 120, 100, 200, 20) GUICtrlCreateLabel("Quốc gia:", 10, 130, 100, 20) Local $inputCountry = GUICtrlCreateInput("", 120, 130, 200, 20) Local $btnSubmit = GUICtrlCreateButton("Xác nhận", 50, 200, 100, 30) Local $btnCancel = GUICtrlCreateButton("Hủy", 200, 200, 100, 30) GUISetState(@SW_SHOW, $hRegisterGUI) ; Biến kiểm tra trạng thái Local $bFormValid = True ; Gán phím Enter cho nút Xác nhận ;HotKeySet("{ENTER}", "SubmitRegisterForm") While 1 Local $nRegisterMsg = GUIGetMsg() Switch $nRegisterMsg Case $GUI_EVENT_CLOSE GUIDelete($hRegisterGUI) Return Case $btnCancel GUIDelete($hRegisterGUI) Return Case $btnSubmit ; Lấy dữ liệu từ các ô nhập Local $sID = GUICtrlRead($inputID) Local $sPass = GUICtrlRead($inputPass) Local $sEmail = GUICtrlRead($inputEmail) Local $sPhone = GUICtrlRead($inputPhone) Local $sCountry = GUICtrlRead($inputCountry) ; Kiểm tra ID hợp lệ $bFormValid = True ; Reset lại giá trị của biến $bFormValid If Not IsValidID($sID) Then MsgBox(16, "Lỗi", "ID không hợp lệ! ID phải có ít nhất 6 ký tự và chỉ chứa chữ và số, không có dấu, khoảng trắng và ký tự đặc biệt.") $bFormValid = False EndIf ; Kiểm tra mật khẩu hợp lệ If Not IsValidPassword($sPass) Then MsgBox(16, "Lỗi", "Mật khẩu không hợp lệ! Mật khẩu không được chứa khoảng trắng hoặc dấu.") $bFormValid = False EndIf ; Kiểm tra email hợp lệ If Not IsValidEmail($sEmail) Then MsgBox(16, "Lỗi", "Email không hợp lệ! Vui lòng nhập email đúng định dạng.") $bFormValid = False EndIf ; Kiểm tra số điện thoại hợp lệ If Not IsValidPhone($sPhone) Then MsgBox(16, "Lỗi", "Số điện thoại không hợp lệ! Vui lòng nhập số điện thoại hợp lệ.") $bFormValid = False EndIf ; Kiểm tra quốc gia hợp lệ If Not IsValidCountry($sCountry) Then MsgBox(16, "Lỗi", "Quốc gia không hợp lệ! Quốc gia chỉ được chứa chữ và khoảng trắng.") $bFormValid = False EndIf ; Kiểm tra thông tin If $sID = "" Or $sPass = "" Or $sEmail = "" Or $sPhone = "" Or $sCountry = "" Then MsgBox(16, "Lỗi", "Vui lòng điền đầy đủ thông tin!") $bFormValid = False EndIf ; Nếu tất cả hợp lệ thì lưu thông tin If $bFormValid Then ; Lưu vào file .ini IniWrite($sFilePath, "Users", $sID, $sPass & "|" & $sEmail & "|" & $sPhone & "|" & $sCountry) MsgBox(64, "Thành công", "Đăng ký thành công!") GUIDelete($hRegisterGUI) Return EndIf EndSwitch WEnd EndFunc ; Kiểm tra ID hợp lệ (Ít nhất 6 ký tự, không có dấu, khoảng trắng và ký tự đặc biệt) Func IsValidID($sID) ; Biểu thức chính quy kiểm tra ID hợp lệ Local $sPattern = "^[a-zA-Z0-9]{6,}$" ; ID phải có ít nhất 6 ký tự và chỉ chứa chữ và số Return StringRegExp($sID, $sPattern) EndFunc ; Kiểm tra mật khẩu hợp lệ (Không chứa khoảng trắng và dấu) Func IsValidPassword($sPass) ; Biểu thức chính quy kiểm tra mật khẩu hợp lệ Local $sPattern = "^[^\x20\x21\x23-\x2B\x2D\x2E\x2F\x3A-\x3B\x3C\x3D\x3F\x5C\x5E\x5F\x60\x7B\x7C\x7D\x7E\x22\x27]+$" Return StringRegExp($sPass, $sPattern) EndFunc ; Kiểm tra email hợp lệ Func IsValidEmail($sEmail) ; Biểu thức chính quy kiểm tra email hợp lệ Local $sPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" Return StringRegExp($sEmail, $sPattern) EndFunc ; Kiểm tra số điện thoại hợp lệ Func IsValidPhone($sPhone) ; Biểu thức chính quy kiểm tra số điện thoại hợp lệ Local $sPattern = "^\+?\d{10,15}$" Return StringRegExp($sPhone, $sPattern) EndFunc ; Kiểm tra quốc gia hợp lệ Func IsValidCountry($sCountry) ; Biểu thức chính quy kiểm tra quốc gia hợp lệ Local $sPattern = "^[a-zA-Z\s]+$" Return StringRegExp($sCountry, $sPattern) EndFunc ; Hàm Đăng nhập Func Login() Local $sUsername = GUICtrlRead($inputUsername) Local $sPassword = GUICtrlRead($inputPassword) ; Kiểm tra thông tin đăng nhập If FileExists($sFilePath) Then Local $sUserData = IniRead($sFilePath, "Users", $sUsername, "") If $sUserData <> "" Then Local $aUserInfo = StringSplit($sUserData, "|") If $aUserInfo[1] = $sPassword Then MsgBox(64, "Đăng nhập thành công", "Chào mừng, " & $sUsername) ; Hiển thị ID người dùng đã đăng nhập GUICtrlSetState($lblUserID, $GUI_SHOW) GUICtrlSetData($lblUserID, "ID: " & $sUsername) ; Ẩn các trường nhập liệu và nút đăng nhập, đăng ký GUICtrlSetState($inputUsername, $GUI_HIDE) GUICtrlSetState($inputPassword, $GUI_HIDE) GUICtrlSetState($btnLogin, $GUI_HIDE) GUICtrlSetState($btnRegister, $GUI_HIDE) ; Ẩn các label "Tên đăng nhập" và "Mật khẩu" GUICtrlSetState($lblUsernameText, $GUI_HIDE) GUICtrlSetState($lblPasswordText, $GUI_HIDE) ; Hiển thị nút đăng xuất GUICtrlSetState($btnLogout, $GUI_SHOW) Else MsgBox(16, "Đăng nhập thất bại", "Mật khẩu sai.") EndIf Else MsgBox(16, "Đăng nhập thất bại", "Tên đăng nhập không tồn tại.") EndIf EndIf EndFunc ; Hàm Đăng xuất Func Logout() GUICtrlSetState($inputUsername, $GUI_SHOW) GUICtrlSetState($inputPassword, $GUI_SHOW) GUICtrlSetState($btnLogin, $GUI_SHOW) GUICtrlSetState($btnRegister, $GUI_SHOW) GUICtrlSetState($lblUsernameText, $GUI_SHOW) GUICtrlSetState($lblPasswordText, $GUI_SHOW) GUICtrlSetState($lblUserID, $GUI_HIDE) GUICtrlSetState($btnLogout, $GUI_HIDE) EndFunc please help. Thanks How to add function to check if ID, email, phone number already exist when registering and to encrypt password before saving to users.ini file Link to comment Share on other sites More sharing options...
argumentum Posted November 17 Share Posted November 17 Spoiler expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; File stores user information Global $sFilePath = @ScriptDir & "\users.ini" ; Create main interface GUICreate("Login", 300, 150) $lblUsernameText = GUICtrlCreateLabel("Username:", 10, 10, 100, 20) $inputUsername = GUICtrlCreateInput("", 120, 10, 150, 20) $lblPasswordText = GUICtrlCreateLabel("Password:", 10, 40, 100, 20) $inputPassword = GUICtrlCreateInput("", 120, 40, 150, 20, $ES_PASSWORD) $btnLogin = GUICtrlCreateButton("Login", 10, 80, 130, 30) $btnRegister = GUICtrlCreateButton("Register", 150, 80, 130, 30) $lblStatus = GUICtrlCreateLabel("", 10, 120, 270, 20) GUISetState(@SW_SHOW) ; Label ID login and logout button $lblUserID = GUICtrlCreateLabel("", 50, 50, 270, 20) $btnLogout = GUICtrlCreateButton("Logout", 100, 100, 100, 30) GUICtrlSetState($btnLogout, $GUI_HIDE) ; Hide the logout button GUICtrlSetState($lblUserID, $GUI_HIDE) ; Hide label "Login ID" ; Assign the Enter key to the login button HotKeySet("{ENTER}", "Login") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnRegister ShowRegisterGUI() Case $btnLogin Login() Case $btnLogout Logout() EndSwitch WEnd ; The function displays the Registration interface Func ShowRegisterGUI() ; Delete old error messages if any GUICtrlSetData($lblStatus, "") ; Create registration interface Local $hRegisterGUI = GUICreate("Register account", 350, 300) GUICtrlCreateLabel("ID:", 10, 10, 100, 20) Local $inputID = GUICtrlCreateInput("", 120, 10, 200, 20) GUICtrlCreateLabel("Password:", 10, 40, 100, 20) Local $inputPass = GUICtrlCreateInput("", 120, 40, 200, 20, $ES_PASSWORD) GUICtrlCreateLabel("Email:", 10, 70, 100, 20) Local $inputEmail = GUICtrlCreateInput("", 120, 70, 200, 20) GUICtrlCreateLabel("Phone number:", 10, 100, 100, 20) Local $inputPhone = GUICtrlCreateInput("", 120, 100, 200, 20) GUICtrlCreateLabel("Country:", 10, 130, 100, 20) Local $inputCountry = GUICtrlCreateInput("", 120, 130, 200, 20) Local $btnSubmit = GUICtrlCreateButton("Confirm", 50, 200, 100, 30) Local $btnCancel = GUICtrlCreateButton("Cancel", 200, 200, 100, 30) GUISetState(@SW_SHOW, $hRegisterGUI) ; Status check variable Local $bFormValid = True ; Assign the Enter key to the Confirm button ;HotKeySet("{ENTER}", "SubmitRegisterForm") While 1 Local $nRegisterMsg = GUIGetMsg() Switch $nRegisterMsg Case $GUI_EVENT_CLOSE GUIDelete($hRegisterGUI) Return Case $btnCancel GUIDelete($hRegisterGUI) Return Case $btnSubmit ; Get data from input cells Local $sID = GUICtrlRead($inputID) Local $sPass = GUICtrlRead($inputPass) Local $sEmail = GUICtrlRead($inputEmail) Local $sPhone = GUICtrlRead($inputPhone) Local $sCountry = GUICtrlRead($inputCountry) ; Check for valid ID $bFormValid = True ; Reset the value of the $bFormValid variable If Not IsValidID($sID) Then MsgBox(16, "Error", "Invalid ID! ID must be at least 6 characters and contain only letters and numbers, no accents, spaces and special characters.") $bFormValid = False EndIf ; Check the password is valid If Not IsValidPassword($sPass) Then MsgBox(16, "Error", "Invalid password! Password cannot contain spaces or accents.") $bFormValid = False EndIf ; Check for valid email If Not IsValidEmail($sEmail) Then MsgBox(16, "Error", "Invalid email! Please enter email in the correct format.") $bFormValid = False EndIf ; Check the phone number is valid If Not IsValidPhone($sPhone) Then MsgBox(16, "Error", "Invalid phone number! Please enter a valid phone number.") $bFormValid = False EndIf ; Check for valid country If Not IsValidCountry($sCountry) Then MsgBox(16, "Error", "Invalid country! Country must contain only letters and spaces.") $bFormValid = False EndIf ; Check information If $sID = "" Or $sPass = "" Or $sEmail = "" Or $sPhone = "" Or $sCountry = "" Then MsgBox(16, "Error", "Please fill in all information!") $bFormValid = False EndIf ; If all is valid, save the information If $bFormValid Then ; Save to .ini file IniWrite($sFilePath, "Users", $sID, $sPass & "|" & $sEmail & "|" & $sPhone & "|" & $sCountry) MsgBox(64, "Success", "Successful registration!") GUIDelete($hRegisterGUI) Return EndIf EndSwitch WEnd EndFunc ; Check valid ID (At least 6 characters, no accents, spaces and special characters) Func IsValidID($sID) ; Regular expression checks for a valid ID Local $sPattern = "^[a-zA-Z0-9]{6,}$" ; ID must be at least 6 characters and contain only letters and numbers Return StringRegExp($sID, $sPattern) EndFunc ; Check valid password (Does not contain spaces or accents) Func IsValidPassword($sPass) ; Regular expression checks for a valid password Local $sPattern = "^[^\x20\x21\x23-\x2B\x2D\x2E\x2F\x3A-\x3B\x3C\x3D\x3F\x5C\x5E\x5F\x60\x7B\x7C\x7D\x7E \x22\x27]+$" Return StringRegExp($sPass, $sPattern) EndFunc ; Check for valid email Func IsValidEmail($sEmail) ; Regular expression checks for a valid email Local $sPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" Return StringRegExp($sEmail, $sPattern) EndFunc ; Check the phone number is valid Func IsValidPhone($sPhone) ; Regular expression checks for a valid phone number Local $sPattern = "^\+?\d{10,15}$" Return StringRegExp($sPhone, $sPattern) EndFunc ; Check for valid country Func IsValidCountry($sCountry) ; Regular expression checks for valid country Local $sPattern = "^[a-zA-Z\s]+$" Return StringRegExp($sCountry, $sPattern) EndFunc ; Login Function Func Login() Local $sUsername = GUICtrlRead($inputUsername) Local $sPassword = GUICtrlRead($inputPassword) ; Check login information If FileExists($sFilePath) Then Local $sUserData = IniRead($sFilePath, "Users", $sUsername, "") If $sUserData <> "" Then Local $aUserInfo = StringSplit($sUserData, "|") If $aUserInfo[1] = $sPassword Then MsgBox(64, "Successful login", "Welcome, " & $sUsername) ; Displays the logged in user ID GUICtrlSetState($lblUserID, $GUI_SHOW) GUICtrlSetData($lblUserID, "ID: " & $sUsername) ; Hide input fields and login and registration buttons GUICtrlSetState($inputUsername, $GUI_HIDE) GUICtrlSetState($inputPassword, $GUI_HIDE) GUICtrlSetState($btnLogin, $GUI_HIDE) GUICtrlSetState($btnRegister, $GUI_HIDE) ; Hide the labels "Username" and "Password" GUICtrlSetState($lblUsernameText, $GUI_HIDE) GUICtrlSetState($lblPasswordText, $GUI_HIDE) ; Show logout button GUICtrlSetState($btnLogout, $GUI_SHOW) Else MsgBox(16, "Login failed", "Wrong password.") EndIf Else MsgBox(16, "Login failed", "Username does not exist.") EndIf EndIf EndFunc ; Ham Log out Func Logout() GUICtrlSetState($inputUsername, $GUI_SHOW) GUICtrlSetState($inputPassword, $GUI_SHOW) GUICtrlSetState($btnLogin, $GUI_SHOW) GUICtrlSetState($btnRegister, $GUI_SHOW) GUICtrlSetState($lblUsernameText, $GUI_SHOW) GUICtrlSetState($lblPasswordText, $GUI_SHOW) GUICtrlSetState($lblUserID, $GUI_HIDE) GUICtrlSetState($btnLogout, $GUI_HIDE) EndFunc 1 hour ago, 1stPK said: How to add function to check if ID, email, phone number already exist when registering and to encrypt password before saving to users.ini file I ran the code and it looks to have that. Now, the encryption. What are you looking to hide that from ? How secure you'd like that to be ? And do please translate the code 1stPK 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
1stPK Posted November 18 Author Share Posted November 18 4 hours ago, argumentum said: Reveal hidden contents expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; File stores user information Global $sFilePath = @ScriptDir & "\users.ini" ; Create main interface GUICreate("Login", 300, 150) $lblUsernameText = GUICtrlCreateLabel("Username:", 10, 10, 100, 20) $inputUsername = GUICtrlCreateInput("", 120, 10, 150, 20) $lblPasswordText = GUICtrlCreateLabel("Password:", 10, 40, 100, 20) $inputPassword = GUICtrlCreateInput("", 120, 40, 150, 20, $ES_PASSWORD) $btnLogin = GUICtrlCreateButton("Login", 10, 80, 130, 30) $btnRegister = GUICtrlCreateButton("Register", 150, 80, 130, 30) $lblStatus = GUICtrlCreateLabel("", 10, 120, 270, 20) GUISetState(@SW_SHOW) ; Label ID login and logout button $lblUserID = GUICtrlCreateLabel("", 50, 50, 270, 20) $btnLogout = GUICtrlCreateButton("Logout", 100, 100, 100, 30) GUICtrlSetState($btnLogout, $GUI_HIDE) ; Hide the logout button GUICtrlSetState($lblUserID, $GUI_HIDE) ; Hide label "Login ID" ; Assign the Enter key to the login button HotKeySet("{ENTER}", "Login") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnRegister ShowRegisterGUI() Case $btnLogin Login() Case $btnLogout Logout() EndSwitch WEnd ; The function displays the Registration interface Func ShowRegisterGUI() ; Delete old error messages if any GUICtrlSetData($lblStatus, "") ; Create registration interface Local $hRegisterGUI = GUICreate("Register account", 350, 300) GUICtrlCreateLabel("ID:", 10, 10, 100, 20) Local $inputID = GUICtrlCreateInput("", 120, 10, 200, 20) GUICtrlCreateLabel("Password:", 10, 40, 100, 20) Local $inputPass = GUICtrlCreateInput("", 120, 40, 200, 20, $ES_PASSWORD) GUICtrlCreateLabel("Email:", 10, 70, 100, 20) Local $inputEmail = GUICtrlCreateInput("", 120, 70, 200, 20) GUICtrlCreateLabel("Phone number:", 10, 100, 100, 20) Local $inputPhone = GUICtrlCreateInput("", 120, 100, 200, 20) GUICtrlCreateLabel("Country:", 10, 130, 100, 20) Local $inputCountry = GUICtrlCreateInput("", 120, 130, 200, 20) Local $btnSubmit = GUICtrlCreateButton("Confirm", 50, 200, 100, 30) Local $btnCancel = GUICtrlCreateButton("Cancel", 200, 200, 100, 30) GUISetState(@SW_SHOW, $hRegisterGUI) ; Status check variable Local $bFormValid = True ; Assign the Enter key to the Confirm button ;HotKeySet("{ENTER}", "SubmitRegisterForm") While 1 Local $nRegisterMsg = GUIGetMsg() Switch $nRegisterMsg Case $GUI_EVENT_CLOSE GUIDelete($hRegisterGUI) Return Case $btnCancel GUIDelete($hRegisterGUI) Return Case $btnSubmit ; Get data from input cells Local $sID = GUICtrlRead($inputID) Local $sPass = GUICtrlRead($inputPass) Local $sEmail = GUICtrlRead($inputEmail) Local $sPhone = GUICtrlRead($inputPhone) Local $sCountry = GUICtrlRead($inputCountry) ; Check for valid ID $bFormValid = True ; Reset the value of the $bFormValid variable If Not IsValidID($sID) Then MsgBox(16, "Error", "Invalid ID! ID must be at least 6 characters and contain only letters and numbers, no accents, spaces and special characters.") $bFormValid = False EndIf ; Check the password is valid If Not IsValidPassword($sPass) Then MsgBox(16, "Error", "Invalid password! Password cannot contain spaces or accents.") $bFormValid = False EndIf ; Check for valid email If Not IsValidEmail($sEmail) Then MsgBox(16, "Error", "Invalid email! Please enter email in the correct format.") $bFormValid = False EndIf ; Check the phone number is valid If Not IsValidPhone($sPhone) Then MsgBox(16, "Error", "Invalid phone number! Please enter a valid phone number.") $bFormValid = False EndIf ; Check for valid country If Not IsValidCountry($sCountry) Then MsgBox(16, "Error", "Invalid country! Country must contain only letters and spaces.") $bFormValid = False EndIf ; Check information If $sID = "" Or $sPass = "" Or $sEmail = "" Or $sPhone = "" Or $sCountry = "" Then MsgBox(16, "Error", "Please fill in all information!") $bFormValid = False EndIf ; If all is valid, save the information If $bFormValid Then ; Save to .ini file IniWrite($sFilePath, "Users", $sID, $sPass & "|" & $sEmail & "|" & $sPhone & "|" & $sCountry) MsgBox(64, "Success", "Successful registration!") GUIDelete($hRegisterGUI) Return EndIf EndSwitch WEnd EndFunc ; Check valid ID (At least 6 characters, no accents, spaces and special characters) Func IsValidID($sID) ; Regular expression checks for a valid ID Local $sPattern = "^[a-zA-Z0-9]{6,}$" ; ID must be at least 6 characters and contain only letters and numbers Return StringRegExp($sID, $sPattern) EndFunc ; Check valid password (Does not contain spaces or accents) Func IsValidPassword($sPass) ; Regular expression checks for a valid password Local $sPattern = "^[^\x20\x21\x23-\x2B\x2D\x2E\x2F\x3A-\x3B\x3C\x3D\x3F\x5C\x5E\x5F\x60\x7B\x7C\x7D\x7E \x22\x27]+$" Return StringRegExp($sPass, $sPattern) EndFunc ; Check for valid email Func IsValidEmail($sEmail) ; Regular expression checks for a valid email Local $sPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" Return StringRegExp($sEmail, $sPattern) EndFunc ; Check the phone number is valid Func IsValidPhone($sPhone) ; Regular expression checks for a valid phone number Local $sPattern = "^\+?\d{10,15}$" Return StringRegExp($sPhone, $sPattern) EndFunc ; Check for valid country Func IsValidCountry($sCountry) ; Regular expression checks for valid country Local $sPattern = "^[a-zA-Z\s]+$" Return StringRegExp($sCountry, $sPattern) EndFunc ; Login Function Func Login() Local $sUsername = GUICtrlRead($inputUsername) Local $sPassword = GUICtrlRead($inputPassword) ; Check login information If FileExists($sFilePath) Then Local $sUserData = IniRead($sFilePath, "Users", $sUsername, "") If $sUserData <> "" Then Local $aUserInfo = StringSplit($sUserData, "|") If $aUserInfo[1] = $sPassword Then MsgBox(64, "Successful login", "Welcome, " & $sUsername) ; Displays the logged in user ID GUICtrlSetState($lblUserID, $GUI_SHOW) GUICtrlSetData($lblUserID, "ID: " & $sUsername) ; Hide input fields and login and registration buttons GUICtrlSetState($inputUsername, $GUI_HIDE) GUICtrlSetState($inputPassword, $GUI_HIDE) GUICtrlSetState($btnLogin, $GUI_HIDE) GUICtrlSetState($btnRegister, $GUI_HIDE) ; Hide the labels "Username" and "Password" GUICtrlSetState($lblUsernameText, $GUI_HIDE) GUICtrlSetState($lblPasswordText, $GUI_HIDE) ; Show logout button GUICtrlSetState($btnLogout, $GUI_SHOW) Else MsgBox(16, "Login failed", "Wrong password.") EndIf Else MsgBox(16, "Login failed", "Username does not exist.") EndIf EndIf EndFunc ; Ham Log out Func Logout() GUICtrlSetState($inputUsername, $GUI_SHOW) GUICtrlSetState($inputPassword, $GUI_SHOW) GUICtrlSetState($btnLogin, $GUI_SHOW) GUICtrlSetState($btnRegister, $GUI_SHOW) GUICtrlSetState($lblUsernameText, $GUI_SHOW) GUICtrlSetState($lblPasswordText, $GUI_SHOW) GUICtrlSetState($lblUserID, $GUI_HIDE) GUICtrlSetState($btnLogout, $GUI_HIDE) EndFunc I ran the code and it looks to have that. Now, the encryption. What are you looking to hide that from ? How secure you'd like that to be ? And do please translate the code I want to check for duplicate account and Email, or some other information when new user register. and add some way to encrypt the user's password before saving it to the users.ini file. then it will compare it with the password of the user logging in the future Link to comment Share on other sites More sharing options...
argumentum Posted November 18 Share Posted November 18 56 minutes ago, 1stPK said: I want to check for duplicate account and Email, Are you going to set up a web site or in a local network ? That looks confused ? What's the confusion about ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
1stPK Posted November 18 Author Share Posted November 18 1 hour ago, argumentum said: Are you going to set up a web site or in a local network ? That looks confused ? What's the confusion about ? bạn thật sự không hiểu tôi nói gì? Link to comment Share on other sites More sharing options...
argumentum Posted November 18 Share Posted November 18 47 minutes ago, 1stPK said: bạn thật sự không hiểu tôi nói gì? No I don't but don't matter. Got other things to so. Cheers 1stPK 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
1stPK Posted November 18 Author Share Posted November 18 1 hour ago, argumentum said: Không, tôi không nhưng không quan trọng. Tôi còn nhiều việc khác phải làm. Chúc vui vẻ thanks Link to comment Share on other sites More sharing options...
1stPK Posted Wednesday at 06:22 PM Author Share Posted Wednesday at 06:22 PM (edited) On 11/18/2024 at 10:46 AM, argumentum said: No I don't but don't matter. Got other things to so. Cheers expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <GDIPlus.au3> #include <WinAPIGdi.au3> #include <String.au3> ; ===== Đặt đường dẫn tệp ===== Global $sDir = @AppDataDir & "\Test" ; Thư mục lưu tệp Global $sFilePath = $sDir & "\users.ini" ; Kiểm tra và tạo thư mục nếu chưa tồn tại If Not FileExists($sDir) Then DirCreate($sDir) EndIf ; ===== Hàm chính - Đăng nhập ===== Func _MainLogin() Local $hLoginGUI = GUICreate("Đăng nhập", 300, 200) GUISetBkColor(0x333333) Local $hideInput = GUICtrlCreateInput("", 0, 0, 0, 0) GUICtrlCreateLabel("Test - [2024] - [By: 1stPK]", 50, 10, 200, 20) GUICtrlSetColor(-1, 0x19FFCC) GUICtrlCreateLabel("Account:", 5, 50, 80, 20) GUICtrlSetColor(-1, 0x19FF7F) Local $idInput = GUICtrlCreateInput("", 60, 50, 176, 20) _GUICtrlEdit_SetCueBanner($idInput, "Account ID") GUICtrlCreateLabel("Password:", 5, 80, 80, 20) GUICtrlSetColor(-1, 0x19FF7F) GUICtrlCreateLabel("", 58, 79, 180, 19, $SS_BLACKFRAME) GUICtrlSetState(-1, $GUI_DISABLE) Local $pwInput = GUICtrlCreateInput("", 60, 80, 154, 17, $ES_PASSWORD, $WS_EX_TOOLWINDOW) Local $idEye = GUICtrlCreatePic(@ScriptDir & "\item_images\Hide.bmp", 214, 80, 22, 17), $bHide = True Local $iDefault = GUICtrlSendMsg($pwInput, $EM_GETPASSWORDCHAR, 0, 0) _GUICtrlEdit_SetCueBanner($pwInput, "Password") Local $btnLogin = GUICtrlCreateButton("Đăng nhập", 50, 120, 100, 30) GUICtrlSetBkColor(-1, 0xFF00FF) Local $btnRegister = GUICtrlCreateButton("Đăng ký", 160, 120, 100, 30) GUICtrlSetBkColor(-1, 0x19FF7F) ; Thêm dòng chữ bản quyền ở góc dưới cùng $linkFB = GUICtrlCreateLabel("Bản quyền © 2024 Test [By-1stPK]", 20, 180, 230, 20) GUICtrlSetColor(-1, 0x19FF7F) ; Màu chữ GUICtrlSetFont(-1, 8, 800, 0, "Arial") ; Phông chữ và kích thước GUISetState(@SW_SHOW, $hLoginGUI) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ; Đóng giao diện đăng nhập Case $btnLogin Local $username = StringStripWS(GUICtrlRead($idInput), 3) Local $password = StringStripWS(GUICtrlRead($pwInput), 3) ; Kiểm tra thông tin đăng nhập If $username = "" Or $password = "" Then MsgBox(16, "Lỗi", "Tài khoản và mật khẩu không được để trống!") ContinueLoop EndIf If _VerifyLogin($username, $password) Then GUIDelete($hLoginGUI) MsgBox(64, "Thông báo", "Đăng nhập thành công!") Return True Else MsgBox(16, "Thông báo", "Thông tin đăng nhập không đúng!") EndIf Case $btnRegister GUIDelete($hLoginGUI) _RegisterAccount() ; Chuyển sang giao diện đăng ký Case $linkFB ShellExecute("https://www.facebook.com/1stPK.MU") Case $idEye $bHide = Not $bHide GUICtrlSetImage($idEye, $bHide ? @ScriptDir & "\item_images\Hide.bmp": @ScriptDir & "\item_images\Show.bmp") GUICtrlSendMsg($pwInput, $EM_SETPASSWORDCHAR, $bHide ? $iDefault : 0, 0) _WinAPI_RedrawWindow(GUICtrlGetHandle($pwInput)) EndSwitch WEnd EndFunc ; ===== Hàm xác thực đăng nhập ===== Func _VerifyLogin($username, $password) If FileExists($sFilePath) Then Local $storedPassword = IniRead($sFilePath, $username, "Password", "") If $password = $storedPassword Then Return True EndIf EndIf Return False EndFunc ; ===== Giao diện đăng ký ===== Func _RegisterAccount() Local $hRegisterGUI = GUICreate("Đăng ký tài khoản", 350, 300) GUISetBkColor(0x333333) Local $hideInput1 = GUICtrlCreateInput("", 0, 0, 0, 0) GUICtrlCreateLabel("Đăng ký tài khoản mới", 100, 10, 150, 20) GUICtrlSetColor(-1, 0x19FFCC) GUICtrlCreateLabel("Account:", 5, 50, 80, 20) GUICtrlSetColor(-1, 0x19FF7F) Local $idInput = GUICtrlCreateInput("", 130, 50, 170, 20) _GUICtrlEdit_SetCueBanner($idInput, "Account ID") GUICtrlCreateLabel("Email:", 5, 80, 80, 20) GUICtrlSetColor(-1, 0x19FF7F) Local $emailInput = GUICtrlCreateInput("", 130, 80, 170, 20) _GUICtrlEdit_SetCueBanner($emailInput, "Enter Email") GUICtrlCreateLabel("Password:", 5, 110, 80, 20) GUICtrlSetColor(-1, 0x19FF7F) Local $pwInput = GUICtrlCreateInput("", 130, 110, 170, 20, 0x0020) _GUICtrlEdit_SetCueBanner($pwInput, "Enter password") GUICtrlCreateLabel("Confirm Password:", 5, 140, 120, 20) GUICtrlSetColor(-1, 0x19FF7F) Local $pwConfirmInput = GUICtrlCreateInput("", 130, 140, 170, 20, 0x0020) _GUICtrlEdit_SetCueBanner($pwConfirmInput, "Re-enter password") Local $btnSubmit = GUICtrlCreateButton("Đăng ký", 120, 200, 100, 30) GUICtrlSetBkColor(-1, 0x19FF7F) GUISetState(@SW_SHOW, $hRegisterGUI) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hRegisterGUI) _MainLogin() Case $btnSubmit Local $username = StringStripWS(GUICtrlRead($idInput), 6) Local $email = StringStripWS(GUICtrlRead($emailInput), 3) Local $password = GUICtrlRead($pwInput) Local $confirmPassword = GUICtrlRead($pwConfirmInput) ; Kiểm tra đầu vào If StringLen($username) < 6 Then MsgBox(16, "Lỗi", "Tài khoản phải có ít nhất 6 ký tự.") ElseIf Not _IsValidEmail($email) Then MsgBox(16, "Lỗi", "Email không hợp lệ.") ElseIf StringLen($password) < 5 Then MsgBox(16, "Lỗi", "Mật khẩu phải có ít nhất 5 ký tự.") ElseIf $password <> $confirmPassword Then MsgBox(16, "Lỗi", "Mật khẩu xác nhận không khớp.") Else If _SaveAccount($username, $password, $email) Then MsgBox(64, "Thông báo", "Đăng ký thành công!") GUIDelete($hRegisterGUI) _MainLogin() Else MsgBox(16, "Lỗi", "Tài khoản đã tồn tại!") EndIf EndIf EndSwitch WEnd EndFunc ; ===== Hàm kiểm tra email hợp lệ ===== Func _IsValidEmail($email) Return StringRegExp($email, "^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$") EndFunc ; ===== Hàm lưu tài khoản ===== Func _SaveAccount($username, $password, $email) If FileExists($sFilePath) Then If IniRead($sFilePath, $username, "Password", "") <> "" Then Return False ; Tài khoản đã tồn tại EndIf EndIf ; Lưu tài khoản và email IniWrite($sFilePath, $username, "Password", $password) IniWrite($sFilePath, $username, "Email", $email) ; Ẩn tệp để tăng bảo mật FileSetAttrib($sFilePath, "+H") Return True EndFunc ; ===== Điểm bắt đầu chương trình ===== If Not _MainLogin() Then Exit ; Thoát chương trình nếu đăng nhập không thành công EndIf #include <GUIConstantsEx.au3> ; Tạo GUI chính GUICreate("Giao diện đơn giản", 400, 300) ; Tên cửa sổ, kích thước rộng x cao ; Thêm các thành phần vào GUI GUICtrlCreateLabel("Nhập thông tin:", 20, 20, 100, 20) Local $input = GUICtrlCreateInput("", 130, 20, 200, 20) Local $btnOK = GUICtrlCreateButton("OK", 150, 60, 100, 30) ; Hiển thị GUI GUISetState(@SW_SHOW) ; Vòng lặp để xử lý sự kiện While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ; Thoát chương trình khi đóng cửa sổ Case $btnOK Local $text = GUICtrlRead($input) ; Đọc nội dung trong ô nhập MsgBox(0, "Thông báo", "Bạn đã nhập: " & $text) ; Hiển thị thông báo EndSwitch WEnd thank you so much. your words have given me the motivation to succeed. Edited Wednesday at 06:26 PM by 1stPK Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now