Babban matsalar da ke tattare da kalmar sirri regex ita ce ana iya yin kutse cikin sauki. Mai hacker zai iya amfani da regex don nemo kalmomin shiga sannan ya yi amfani da waษancan kalmomin shiga don samun damar asusu.
var password = "abc123"; var regex = /^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/; if(regex.test(password)) { console.log("Password is valid"); } else { console.log("Password is invalid"); }
Layin farko ya ฦirฦiri maษalli da ake kira โPasswordโ kuma ya sanya darajar โabc123โ gare shi. Layi na biyu ya ฦirฦiri madaidaicin da ake kira "regex" kuma ya sanya ma'anar magana akai-akai. Wannan magana ta yau da kullun tana bincika idan kalmar sirri ta ฦunshi aฦalla lamba ษaya, ฦaramin harafi ษaya, da babban harafi ษaya. Layi na uku yana bincika idan kalmar sirrin da mai amfani ya shigar (an adana shi a cikin maballin โPasswordโ) yayi daidai da kalmar yau da kullun da aka adana a cikin m โregexโ. Idan ya yi, sa'an nan saฦon "Passsword yana aiki" yana nunawa akan na'urar bidiyo. Idan ba haka ba, to ana nuna saฦon โPassword is invalidโ a kan naโurar bidiyo.
regex
Regex babban ษakin karatu ne mai sarrafa rubutu don JavaScript. Yana ba ku damar daidaita alamu a cikin rubutu, kuma ana iya amfani da su don dalilai daban-daban, kamar inganci ko bincike.
JavaScript da kalmomin shiga
ฦaya daga cikin hanyoyin da aka fi sani don adana kalmomin shiga cikin JavaScript shine amfani da mai sarrafa kalmar sirri. Mai sarrafa kalmar sirri yana adana kalmomin shiga a cikin amintacciyar hanya kuma zai iya taimaka maka tuna kalmomin shiga da yawa.