mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 05:47:10 -04:00
1 line
3 KiB
JavaScript
1 line
3 KiB
JavaScript
import{a as f,b as y}from"./chunk-a740628f.js";import{_ as x}from"./chunk-6deddc2e.js";import{d as k,r as b,c as _,j as l,D as d,m as p,q as h,S as w,l as g,E as i,M as m,F as U,U as I,z as L}from"./chunk-449c23a2.js";import"./chunk-9a43cce8.js";import"./chunk-340feaf0.js";function C(t){const[o,e]=t.toString().split("e"),n=Number.parseFloat(o),s=n%1===0?n.toLocaleString():n.toFixed(2);return e?`${s}e${e}`:s}function D({seconds:t}){if(t<=.001)return"Instantly";if(t<=1)return"Less than a second";const o=[{unit:"millenium",secondsInUnit:31536e6,format:C,plural:"millennia"},{unit:"century",secondsInUnit:31536e5,plural:"centuries"},{unit:"decade",secondsInUnit:31536e4,plural:"decades"},{unit:"year",secondsInUnit:31536e3,plural:"years"},{unit:"month",secondsInUnit:2592e3,plural:"months"},{unit:"week",secondsInUnit:604800,plural:"weeks"},{unit:"day",secondsInUnit:86400,plural:"days"},{unit:"hour",secondsInUnit:3600,plural:"hours"},{unit:"minute",secondsInUnit:60,plural:"minutes"},{unit:"second",secondsInUnit:1,plural:"seconds"}];return f.chain(o).map(({unit:e,secondsInUnit:n,plural:s,format:a=f.identity})=>{const r=Math.floor(t/n);return t%=n,r<=0?void 0:`${a(r)} ${r>1?s:e}`}).compact().take(2).join(", ").value()}function E({password:t,guessesPerSecond:o=1e9}){const e=F({password:t}),n=t.length,s=t===""?0:Math.log2(e)*n,a=2**s/o,r=D({seconds:a}),c=Math.min(s/128,1);return{entropy:s,charsetLength:e,passwordLength:n,crackDurationFormatted:r,secondsToCrack:a,score:c}}function F({password:t}){const o=/[a-z]/.test(t),e=/[A-Z]/.test(t),n=/\d/.test(t),s=/\W|_/.test(t);let a=0;return o&&(a+=26),e&&(a+=26),n&&(a+=10),s&&(a+=32),a}const N={flex:"","flex-col":"","gap-3":""},M=i("div",{"op-60":""}," Duration to crack this password with brute force ",-1),S={"text-2xl":"","data-test-id":"crack-duration"},T={"flex-1":"","text-right":"","op-60":""},$={"flex-1":"","text-left":""},B=i("div",{"op-70":""},[i("span",{"font-bold":""},"Note: "),L(" The computed strength is based on the time it would take to crack the password using a brute force approach, it does not take into account the possibility of a dictionary attack. ")],-1),P=k({__name:"password-strength-analyser",setup(t){const o=b(""),e=_(()=>E({password:o.value})),n=_(()=>[{label:"Password length:",value:e.value.passwordLength},{label:"Entropy:",value:Math.round(e.value.entropy*100)/100},{label:"Character set size:",value:e.value.charsetLength},{label:"Score:",value:`${Math.round(e.value.score*100)} / 100`}]);return(s,a)=>{const r=x,c=y;return l(),d("div",N,[p(r,{value:h(o),"onUpdate:value":a[0]||(a[0]=u=>w(o)?o.value=u:null),type:"password",placeholder:"Enter a password...",clearable:"",autofocus:"","raw-text":"","test-id":"password-input"},null,8,["value"]),p(c,{"text-center":""},{default:g(()=>[M,i("div",S,m(h(e).crackDurationFormatted),1)]),_:1}),p(c,null,{default:g(()=>[(l(!0),d(U,null,I(h(n),({label:u,value:v})=>(l(),d("div",{key:u,flex:"","gap-3":""},[i("div",T,m(u),1),i("div",$,m(v),1)]))),128))]),_:1}),B])}}});export{P as default};
|