Mikijs Posted December 28, 2007 Report Share Posted December 28, 2007 (edited) Tātad uztaisiju paroles generetaju kuru velos lietot savam portalam, bet ir tada maza niansite.. amm =/ vinjam butu jadod parole (jauna genereta) ko vinjs arii dara, bet vinjs to paroli dod mainigos garumos, gribeotos lai ta parole ir piem 10 simbolu gara.. <?php function uzvparoli() { $burti = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pw = ''; while ($i <= 7) { $num = rand() % 33; $tmp = substr($burti, $num); $pass = $pw . $tmp; $i++; } return $pass; } $parole = uzv.paroli(); if ($parole) echo 'Jaunā parole: '.$parole; elseif (!$parole) echo 'Ir notikusi kļūda: Nav ģenerēta parole.'; ?> Edited December 28, 2007 by Mikijs Link to comment Share on other sites More sharing options...
andrisp Posted December 28, 2007 Report Share Posted December 28, 2007 Pēc koda spriežot, tur vajag nākt ārā parolēm 8 simbolu garumā nevis mainīgā garumā. Vienkārši nomaini to $i <= 7 uz lielāku ciparu Link to comment Share on other sites More sharing options...
Delfins Posted December 28, 2007 Report Share Posted December 28, 2007 Ērtības labad vari paņemt gatavos libus. Uzģenerēs PSW, ka varēs arī atcerēties. Link to comment Share on other sites More sharing options...
bubu Posted December 28, 2007 Report Share Posted December 28, 2007 Kurā gan gadījumā var izpildīties šī if daļa: elseif (!$parole) ? Un tur kautkā jocīgi - cipars 1 ir "aizmirsts", bet kopējais simbolu skaits ir 34, taču tiek izvēlēti tikai 33 simboli... Iesaku izmantot ASCII tabulas specifiku - burti no a līdz z un cipari no 0 līdz 9 iet pēc kārtas. Link to comment Share on other sites More sharing options...
Delfins Posted December 28, 2007 Report Share Posted December 28, 2007 Starp citu, minētā f-ja vienmēr atgriezīs 1-simbola paroli :) nav nekādas konketenācijas $pass = $pw . $tmp; Link to comment Share on other sites More sharing options...
mounkuls Posted December 29, 2007 Report Share Posted December 29, 2007 Parole ko generes ar tadu kodu vispar bus pedejais rezultats sim te $tmp = substr($burti, $num); vienmer man liekas skatoties pec koda. Bez tam $burti = "abcdefghijkmnopqrstuvwxyz023456789"; ir parasts teksta strings ne masivs, tatad atgriezis $num burtus no stringa sakuma. Es taisiju vienreiz ta: 1. samet masiva simbolus ko generes, 2. ciklaa(cik nu to paroli vajag garu) ar rand izvelk vienu masiva elementu un pieshkir to citam masivam, 3. saliek virkni no otra masiva un atgriezh genereto stringu. viss, un stradaja bez problemam. Link to comment Share on other sites More sharing options...
Lynx Posted December 29, 2007 Report Share Posted December 29, 2007 Tas mounkuls minētais variants, manuprāt, izskatās šādi, pats izmantoju: function create_pass($length = 10) { $pass = ''; $chars = 'AaBbCcDdEeFfIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz1234567890'; for ($i = 0; $i < $length; $i++) { $pass .= $chars{mt_rand(0, strlen($chars)-1)}; } return $pass; } Link to comment Share on other sites More sharing options...
Kavacky Posted December 29, 2007 Report Share Posted December 29, 2007 Bez tam $burti = "abcdefghijkmnopqrstuvwxyz023456789"; ir parasts teksta strings ne masivsUn kas tad ir strings, ja ne masīvs? Link to comment Share on other sites More sharing options...
marcis Posted December 29, 2007 Report Share Posted December 29, 2007 mans super variants, kas ģenerē diezgan tizlas paroles function password($length=10) { $array1=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); $array2=array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $array3=array("1","2","3","4","5","6","7","8","9","0"); $passw=""; $i=0; while($i < $length) { $arr=rand(1,3); $array="array".$arr; $char = ($arr==3) ? rand(0,9) : rand(0,26); $passw.=$array[$char]; if($array[$char]) ++$i; } return $passw; } Link to comment Share on other sites More sharing options...
marcis Posted December 29, 2007 Report Share Posted December 29, 2007 Kavacky, masīvs ir array(); Link to comment Share on other sites More sharing options...
andrisp Posted December 29, 2007 Report Share Posted December 29, 2007 Varbūt nav pārāk ūberkruti, bet es parasti izlīdzos ar kaut ko šādu: $password = substring(md5(microtime()), rand(0, 5), 10); Link to comment Share on other sites More sharing options...
Kavacky Posted December 29, 2007 Report Share Posted December 29, 2007 Kavacky, masīvs ir array(); "Most string implementations are very similar to variable-length arrays with the entries storing the character codes of corresponding characters." / Wiki / ;) Link to comment Share on other sites More sharing options...
bubu Posted December 29, 2007 Report Share Posted December 29, 2007 Iekš php strings ir masīvs, taču masīvs (array()) nav masīvs - tā ir heštabula. Link to comment Share on other sites More sharing options...
mounkuls Posted December 29, 2007 Report Share Posted December 29, 2007 (edited) Iekš php strings ir masīvs, taču masīvs (array()) nav masīvs - tā ir heštabula. Visu cienu bubu! nopietni. Bet nu es PHP4 domaju ka var skaitas "awewawewewe" ne masiv bet prosta string ar text. Gan jau ka man nav taisniba.Ta ir ja samauchka:) Es patisham atvainojos Hash gan man ar citu pavisdam associacejas, tas ir ir strings ar neatgrieezenisku dekodeshanu. hmm, string ir masivs, bet defineta mainiga vertiba man liekas uzreiz nav array? Varbut man nav taisniba....Es parakstos par to un priecashos par korekcijam. Nopieti, es saku diezgan varbut pat tizli, lasiju php manuali krieviski un maucu augsha chatu pats vadoties pec ta kadu es to gribu. 3 meneshi man tas prasija, smiekligi? nu ja ieesacejam laikam ka normali. Protams,ka man merkis bija uztaisit, ja, tas darbojas. Tas pat darbojas uz failiem, bez datubazes. ehhh, tad kad to taisiju,nebija infa par daudzajiem specsimboliem(ne gkluzhi htmlspecialchars), bet nu iekritu.. Edited December 29, 2007 by mounkuls Link to comment Share on other sites More sharing options...
Aleksejs Posted December 30, 2007 Report Share Posted December 30, 2007 hash funkcija ir tāda funkcija, kas jebkura datuma ievaddatus pārveido uz fiksēta izmēra vērtību. [De]kodēšana un šifrēšana vispārīgā gadījumā nav saistītas ar hash funkcijām. http://en.wikipedia.org/wiki/Hash_function Par hash tabulām (tās apgūst kursā, kas saucas +- "Datu struktūras") http://en.wikipedia.org/wiki/Hash_table Tā par ko Tu visticamāk domāji ir kriptogrāfiska hash funkcija ;) Link to comment Share on other sites More sharing options...
Recommended Posts