Что нового

[Элементы GUI] генератор паролей

ahjkcfout7

Знающий
Сообщения
26
Репутация
6
AutoIt: 3.3.8.1
Версия:

Категория: Элементы GUI,

Описание: Генератор паролей

Код/Пример:
Код:
#include <GuiRichEdit.au3>
#include <String.au3>
#include <Color.au3>
#include <file.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>
#Include <Array.au3>
#include <UpdownConstants.au3>
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
#include <StaticConstants.au3>
HotKeySet("^q", "_Ctrl_Q")
Global   $Lenght,$lenght1,$Chars,$Result,$Chars,$Result,$iRand,$Splited,$Paused,$_rus_alphabet,$_eng_alphabet,$_number,$_other,$rus_alphabet_,$eng_alphabet_,$number_,$other_
$rus_alphabet_="АБВГДЕЖЗИЙКЛМНОПРСТУХФЦЧШЩЬЪЭЫЮЯабвгдежзийклмнопрстухфцчшщьъэыюя"
$eng_alphabet_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
$number_="1234567890"
$other_='!@#$%^&*()_+-=""./\|{}[]<>;,:~`'&"''"
$Win = GUICreate("", 635, 250, 350, 180, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_DLGMODALFRAME)
_WinAPI_SetClassLongEx($Win, $GCL_HICONSM, 0)
_WinAPI_SetClassLongEx($Win, $GCL_HICON, 0)
GUICtrlCreateLabel("password length", 5, 29, 1.8*50)
$Pass_Len = GUICtrlCreateInput (1000,  1.5*60+3, 30-2, 50, 17, 0x2000)
$rus_alphabet= GUICtrlCreateCheckbox ("rus",170, 25)
$eng_alphabet= GUICtrlCreateCheckbox ("eng",220, 25)
$number= GUICtrlCreateCheckbox ("number",270, 25)
$other= GUICtrlCreateCheckbox ("other",335, 25)
GUICtrlSetLimit($Pass_Len, 4)
$reset = GUICtrlCreateButton("Reset", 400, 22, 1.4*50)
$button41 = GUICtrlCreateButton("Generate", 15*30-8+35, 30-8, 1.4*50)
$but_copy = GUICtrlCreateButton("Copy to clip", 15*30-8+44+1.4*50, 30-8, 1.4*50)
$Pass_Use_Symbol = GUICtrlCreateEdit ("",3, 57, 617, 142, 0x0040)
GUISetState(@SW_SHOW, $win)
While True
	Global $msg = GUIGetMsg()
	If  $msg = -3 Then Exit
	If $msg = $rus_alphabet Then
		If GUICtrlRead($rus_alphabet) = $GUI_UNCHECKED Then $_rus_alphabet=""
		If GUICtrlRead($rus_alphabet) = $GUI_CHECKED Then $_rus_alphabet=$rus_alphabet_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	If $msg = $eng_alphabet Then
		If GUICtrlRead($eng_alphabet) = $GUI_UNCHECKED Then $_eng_alphabet=""
		If GUICtrlRead($eng_alphabet) = $GUI_CHECKED Then $_eng_alphabet=$eng_alphabet_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	If $msg = $number Then
		If GUICtrlRead($number) = $GUI_UNCHECKED Then $_number=""
		If GUICtrlRead($number) = $GUI_CHECKED Then $_number=$number_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	if $msg = $other  Then
		If GUICtrlRead($other) = $GUI_UNCHECKED Then $_other=""
		If GUICtrlRead($other) = $GUI_CHECKED Then $_other=$other_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	Endif
	If  $msg = $button41 Then RandPassGen()
	If  $msg = $reset Then
		$_rus_alphabet=$rus_alphabet_
		$_eng_alphabet=$eng_alphabet_
		$_number=$number_
		$_other=$other_
		GUICtrlSetData($Pass_Use_Symbol,"")
		GUICtrlSetState($rus_alphabet, $GUI_UNCHECKED)
		GUICtrlSetState($eng_alphabet, $GUI_UNCHECKED)
		GUICtrlSetState($number, $GUI_UNCHECKED)
		GUICtrlSetState($other, $GUI_UNCHECKED)
	EndIf
	If $msg = $but_copy Then ClipPut($Result)
	Sleep(10)
WEnd
Func RandPassGen()
	$Lenght = GUICtrlRead($Pass_Len)
	$lenght1 = StringIsInt($Lenght)
	$Chars = GUICtrlRead($Pass_Use_Symbol)
	If  $lenght1 = 1 And $Lenght <= 9999 And $Lenght > 0 Then
		$sChars = StringStripWS ($Chars, 8)
		$Splited = StringSplit($sChars, "")
		for $i = 1 to $Lenght
			$iRand = Random(1,UBound($Splited) - 1, 1)
			$Result &= $Splited[$iRand]
		Next
		GUICtrlSetData($Pass_Use_Symbol, $Result)
	EndIf
	GUICtrlSetData($Pass_Use_Symbol, $Result)
EndFunc


Func _Ctrl_Q()
    Exit 0
EndFunc

Файл: http://

Снимок:


История версий:

Источник: autoit-script.ru
Автор(ы):
 

inververs

AutoIT Гуру
Сообщения
2,135
Репутация
465
Хрень.
Длинна пароля 3 буквы, галочки rus end number.
Сгенерировано: UВзВзВUВВUВВВВВВВзВВUВзUзВзВВВ
ни одной цифры...
 
Автор
A

ahjkcfout7

Знающий
Сообщения
26
Репутация
6
печально тебе...у меня норм работает


Добавлено:
Сообщение автоматически объединено:

некоторые неточности были с кнопкой reset
Код:
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

HotKeySet("^q", "_Ctrl_Q")
Global   $Lenght,$lenght1,$Chars,$Result,$Chars,$Result,$iRand,$Splited,$Paused,$_rus_alphabet,$_eng_alphabet,$_number,$_other,$rus_alphabet_,$eng_alphabet_,$number_,$other_
$rus_alphabet_="АБВГДЕЖЗИЙКЛМНОПРСТУХФЦЧШЩЬЪЭЫЮЯабвгдежзийклмнопрстухфцчшщьъэыюя"
$eng_alphabet_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
$number_="1234567890"
$other_='!@#$%^&*()_+-=""./\|{}[]<>;,:~`'&"''"
$Win = GUICreate("", 635, 250, 350, 180, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_DLGMODALFRAME)
_WinAPI_SetClassLongEx($Win, $GCL_HICONSM, 0)
_WinAPI_SetClassLongEx($Win, $GCL_HICON, 0)
GUICtrlCreateLabel("password length", 5, 29, 1.8*50)
$Pass_Len = GUICtrlCreateInput (1000,  1.5*60+3, 30-2, 50, 17, 0x2000)
$rus_alphabet= GUICtrlCreateCheckbox ("rus",170, 25)
$eng_alphabet= GUICtrlCreateCheckbox ("eng",220, 25)
$number= GUICtrlCreateCheckbox ("number",270, 25)
$other= GUICtrlCreateCheckbox ("other",335, 25)
GUICtrlSetLimit($Pass_Len, 4)
$reset = GUICtrlCreateButton("Reset", 400, 22, 1.4*50)
$button41 = GUICtrlCreateButton("Generate", 15*30-8+35, 30-8, 1.4*50)
$but_copy = GUICtrlCreateButton("Copy to clip", 15*30-8+44+1.4*50, 30-8, 1.4*50)
$Pass_Use_Symbol = GUICtrlCreateEdit ("",3, 57, 617, 142, 0x0040)
GUISetState(@SW_SHOW, $win)
While True
	Global $msg = GUIGetMsg()
	If  $msg = -3 Then Exit
	If $msg = $rus_alphabet Then
		If GUICtrlRead($rus_alphabet) = $GUI_UNCHECKED Then $_rus_alphabet=""
		If GUICtrlRead($rus_alphabet) = $GUI_CHECKED Then $_rus_alphabet=$rus_alphabet_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	If $msg = $eng_alphabet Then
		If GUICtrlRead($eng_alphabet) = $GUI_UNCHECKED Then $_eng_alphabet=""
		If GUICtrlRead($eng_alphabet) = $GUI_CHECKED Then $_eng_alphabet=$eng_alphabet_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	If $msg = $number Then
		If GUICtrlRead($number) = $GUI_UNCHECKED Then $_number=""
		If GUICtrlRead($number) = $GUI_CHECKED Then $_number=$number_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	EndIf
	if $msg = $other  Then
		If GUICtrlRead($other) = $GUI_UNCHECKED Then $_other=""
		If GUICtrlRead($other) = $GUI_CHECKED Then $_other=$other_
		GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
	Endif
	If  $msg = $button41 Then RandPassGen()
	If  $msg = $reset Then
		$_rus_alphabet=""
		$_eng_alphabet=""
		$_number=""
		$_other=""
		GUICtrlSetData($Pass_Use_Symbol,"")
		GUICtrlSetState($rus_alphabet, $GUI_UNCHECKED)
		GUICtrlSetState($eng_alphabet, $GUI_UNCHECKED)
		GUICtrlSetState($number, $GUI_UNCHECKED)
		GUICtrlSetState($other, $GUI_UNCHECKED)
		$Result=""
	EndIf
	If $msg = $but_copy Then ClipPut($Result)
	Sleep(10)
WEnd
Func RandPassGen()
	$Lenght = GUICtrlRead($Pass_Len)
	$lenght1 = StringIsInt($Lenght)
	$Chars = GUICtrlRead($Pass_Use_Symbol)
	If  $lenght1 = 1 And $Lenght <= 9999 And $Lenght > 0 Then
		$sChars = StringStripWS ($Chars, 8)
		$Splited = StringSplit($sChars, "")
		for $i = 1 to $Lenght
			$iRand = Random(1,UBound($Splited) - 1, 1)
			$Result &= $Splited[$iRand]
		Next
		GUICtrlSetData($Pass_Use_Symbol, $Result)
	EndIf
	GUICtrlSetData($Pass_Use_Symbol, $Result)
EndFunc


Func _Ctrl_Q()
    Exit 0
EndFunc
 

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5,379
Репутация
2,724
Начало хорошее, но не хватает практики написания программ на AutoIt. Вот некоторые моменты, на которые вам нужно обратить внимание:
  • Глобальные и локальные переменные. Если кратко, то чем меньше глобальных переменных, тем лучше. Также рекомендую всегда использовать опцию MustDeclareVars, это сведет количество ошибок к минимуму.
  • Sleep() в основном цикле не нужна, если есть GUIGetMsg() или TrayGetMsg().
  • Использование Select или Switch для GUIGetMsg() более предпочтительны нежели последовательное сравнение If..Then.
  • Использование в подобных программах Random() без начальной инициализации - SRandom() - моветон.
А так, за попытку "+".
 

firex

AutoIT Гуру
Сообщения
943
Репутация
208
Как альтернатива ( идею кажется у кого-то спер :smile: ):
Код:
Func __RandStr( $iStrLen, $iCase = 0, $iRandLenMax = 6 )
	Local $sRet, $iMin, $iMax, $iNum = 0, $_iCase = $iCase
	; ---
	If $iRandLenMax Then _
		$iStrLen += Random( 0, $iRandLenMax, 1 )

	While StringLen($sRet) < $iStrLen
		Switch $iCase
			Case 0
				$iCase = Random( 1, 3, 1 )
				ContinueLoop
			Case 1
				$iMin = 48
				$iMax = 57
			Case 2
				$iMin = 65
				$iMax = 90
			Case 3
				$iMin = 97
				$iMax = 122
		EndSwitch
		;SRandom( Random( 1, 1488, 1 ) )

		$sRet &= Chr( Random( $iMin, $iMax, 1 ) )
		If Not $_iCase Then _
			$iCase = 0
	WEnd
	; ---
	Return $sRet
EndFunc
 
Автор
A

ahjkcfout7

Знающий
Сообщения
26
Репутация
6
переделал...только про рендом не понятно...
Код:
#include <GUIConstantsEx.au3>
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt("MustDeclareVars",1)
HotKeySet("^q", "_Ctrl_Q")
Global $Result
Local $button41 ,$Pass_Use_Symbol ,$but_copy,$reset ,$reset ,$other,$number,$eng_alphabet,$rus_alphabet, $Pass_Len , $Win, $_rus_alphabet,$_eng_alphabet,$_number,$_other,$rus_alphabet_,$eng_alphabet_,$number_,$other_
$rus_alphabet_="АБВГДЕЖЗИЙКЛМНОПРСТУХФЦЧШЩЬЪЭЫЮЯабвгдежзийклмнопрстухфцчшщьъэыюя"
$eng_alphabet_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
$number_="1234567890"
$other_='!@#$%^&*()_+-=""./\|{}[]<>;,:~`'&"''"
$Win = GUICreate("", 635, 250, 350, 180, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_DLGMODALFRAME)
_WinAPI_SetClassLongEx($Win, $GCL_HICONSM, 0)
_WinAPI_SetClassLongEx($Win, $GCL_HICON, 0)
GUICtrlCreateLabel("password length", 5, 29, 1.8*50)
$Pass_Len = GUICtrlCreateInput (100,  1.5*60+3, 30-2, 50, 17, 0x2000)
$rus_alphabet= GUICtrlCreateCheckbox ("rus",170, 25)
$eng_alphabet= GUICtrlCreateCheckbox ("eng",220, 25)
$number= GUICtrlCreateCheckbox ("number",270, 25)
$other= GUICtrlCreateCheckbox ("other",335, 25)
GUICtrlSetLimit($Pass_Len, 4)
$reset = GUICtrlCreateButton("Reset", 400, 22, 1.4*50)
$button41 = GUICtrlCreateButton("Generate", 15*30-8+35, 30-8, 1.4*50)
$but_copy = GUICtrlCreateButton("Copy to clip", 15*30-8+44+1.4*50, 30-8, 1.4*50)
$Pass_Use_Symbol = GUICtrlCreateEdit ("",3, 57, 617, 142, 0x0040)
GUISetState(@SW_SHOW, $win)
While True
	Global $msg = GUIGetMsg()
	Select
		Case $msg = -3
			Exit
		Case $msg = $rus_alphabet
			If GUICtrlRead($rus_alphabet) = $GUI_UNCHECKED Then $_rus_alphabet=""
			If GUICtrlRead($rus_alphabet) = $GUI_CHECKED Then $_rus_alphabet=$rus_alphabet_
			GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
		Case $msg = $eng_alphabet
			If GUICtrlRead($eng_alphabet) = $GUI_UNCHECKED Then $_eng_alphabet=""
			If GUICtrlRead($eng_alphabet) = $GUI_CHECKED Then $_eng_alphabet=$eng_alphabet_
			GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
		Case $msg = $number
			If GUICtrlRead($number) = $GUI_UNCHECKED Then $_number=""
			If GUICtrlRead($number) = $GUI_CHECKED Then $_number=$number_
			GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
		Case $msg = $other
			If GUICtrlRead($other) = $GUI_UNCHECKED Then $_other=""
			If GUICtrlRead($other) = $GUI_CHECKED Then $_other=$other_
			GUICtrlSetData($Pass_Use_Symbol,$_rus_alphabet&$_eng_alphabet&$_number&$_other)
		Case $msg = $button41
			RandPassGen()
		Case $msg = $reset
			$_rus_alphabet=""
			$_eng_alphabet=""
			$_number=""
			$_other=""
			GUICtrlSetData($Pass_Use_Symbol,"")
			GUICtrlSetState($rus_alphabet, $GUI_UNCHECKED)
			GUICtrlSetState($eng_alphabet, $GUI_UNCHECKED)
			GUICtrlSetState($number, $GUI_UNCHECKED)
			GUICtrlSetState($other, $GUI_UNCHECKED)
			$Result=""
		Case $msg = $but_copy
			ClipPut($Result)
	EndSelect
WEnd
Func RandPassGen()
	Local $Lenght ,$Lenght1 ,$Chars,$sChars,$Splited,$iRand
	$Lenght = GUICtrlRead($Pass_Len)
	$lenght1 = StringIsInt($Lenght)
	$Chars = GUICtrlRead($Pass_Use_Symbol)
	If  $lenght1 = 1 And $Lenght <= 9999 And $Lenght > 0 Then
		$sChars = StringStripWS ($Chars, 8)
		$Splited = StringSplit($sChars, "")
		for $i = 1 to $Lenght
			$iRand = Random(1,UBound($Splited) - 1, 1)
			$Result &= $Splited[$iRand]
		Next
		GUICtrlSetData($Pass_Use_Symbol, $Result)
	EndIf
	GUICtrlSetData($Pass_Use_Symbol, $Result)
EndFunc

Func _Ctrl_Q()
    Exit 0
EndFunc
 
Верх