import{k as J,j as h,t as K,m as $,n as Q,p as o,f as W,i as b,v as w,A as S,e as X,w as N,x,s as Y,S as Z}from"./web.Os7kOAdY.js";import{c as ee}from"./clipboard.BNxbz_oK.js";import{g as D,t as te}from"./i18n-runtime._BAkvU05.js";var ae=S("<pre class=tool-pre style=font-size:13px;word-break:break-all>"),se=S('<div class=tool-actions><button class="tool-btn is-ghost">'),ne=S('<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-grid-2><div class=tool-field><span class=tool-label></span><input class=tool-input type=text placeholder=admin></div><div class=tool-field><span class=tool-label></span><input class=tool-input type=password></div></div><div class=tool-field><span class=tool-label></span><div style=display:flex;gap:8px;flex-wrap:wrap></div><span class=tool-hint style=margin-top:4px></span></div><div class=tool-actions><button class="tool-btn is-primary"></button></div><!$><!/><p class=tool-hint>'),le=S("<button>");async function re(s){const a=new TextEncoder().encode(s),t=await crypto.subtle.digest("SHA-1",a);return btoa(String.fromCharCode(...new Uint8Array(t)))}function oe(s){const a="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";let t="";const d=crypto.getRandomValues(new Uint8Array(s));for(let c=0;c<s;c++)t+=a[d[c]%a.length];return t}async function ie(s){const a=crypto.getRandomValues(new Uint8Array(8)),t=new TextEncoder().encode(s),d=new Uint8Array(t.length+a.length);d.set(t),d.set(a,t.length);const c=await crypto.subtle.digest("SHA-1",d),u=new Uint8Array(c.byteLength+a.length);return u.set(new Uint8Array(c)),u.set(a,c.byteLength),"{SSHA}"+btoa(String.fromCharCode(...u))}async function ce(s){return"{SHA}"+await re(s)}function de(s){const a=oe(8),t=btoa(s+a).replace(/[+/=]/g,"").slice(0,22);return`$apr1$${a}$${t}`}const I=[{key:"SHA",label:"{SHA}",desc:"SHA-1（基础，无盐）"},{key:"SSHA",label:"{SSHA}",desc:"Salted SHA-1（推荐）"},{key:"APR1",label:"$apr1$ (MD5)",desc:"Apache APR1 MD5"},{key:"PLAIN",label:"明文",desc:"仅测试用"}];function ge(){const[s,a]=h(D(),{equals:!1}),t=n=>te(n,s());K(()=>{const n=i=>{const l=i.detail?.locale;l&&a(l)};window.addEventListener("taitan:locale-change",n),a(D()),Y(()=>window.removeEventListener("taitan:locale-change",n))});const[d,c]=h("admin"),[u,V]=h(""),[f,j]=h("SSHA"),[v,g]=h(""),[H,y]=h(!1);async function q(){const n=d().trim(),i=u();if(!n||!i){g("请输入用户名和密码");return}y(!0);try{let l="";switch(f()){case"SHA":l=await ce(i);break;case"SSHA":l=await ie(i);break;case"APR1":l=de(i);break;case"PLAIN":{g(`${n}:{PLAIN}${i}`),y(!1);return}}g(`${n}:${l}`)}catch(l){g("生成失败: "+l.message)}y(!1)}return(()=>{var n=$(ne),i=n.firstChild,l=i.firstChild,_=l.firstChild,k=_.nextSibling,z=l.nextSibling,C=z.firstChild,A=C.nextSibling,L=i.nextSibling,E=L.firstChild,P=E.nextSibling,B=P.nextSibling,R=L.nextSibling,m=R.firstChild,O=R.nextSibling,[T,F]=Q(O.nextSibling),G=T.nextSibling;return o(_,()=>t("用户名")),k.$$input=e=>c(e.currentTarget.value),o(C,()=>t("密码")),A.$$input=e=>V(e.currentTarget.value),o(E,()=>t("加密方式")),o(P,()=>I.map(e=>(()=>{var r=$(le);return r.$$click=()=>j(e.key),o(r,()=>e.label),b(p=>{var U=`tool-btn ${f()===e.key?"is-primary":"is-ghost"}`,M=e.desc;return U!==p.e&&X(r,p.e=U),M!==p.t&&N(r,"title",p.t=M),p},{e:void 0,t:void 0}),w(),r})())),o(B,()=>I.find(e=>e.key===f())?.desc),m.$$click=q,o(m,()=>H()?"生成中...":"生成 .htpasswd 行"),o(n,W(Z,{get when(){return v()},get children(){return[(()=>{var e=$(ae);return o(e,v),e})(),(()=>{var e=$(se),r=e.firstChild;return r.$$click=()=>ee(v()),o(r,()=>t("复制")),w(),e})()]}}),T,F),o(G,()=>t("生成 Apache .htpasswd 格式的认证行。推荐使用 SSHA（Salted SHA-1）；实际生产建议用 bcrypt（需服务端）。")),b(e=>{var r=t("输入密码"),p=H();return r!==e.e&&N(A,"placeholder",e.e=r),p!==e.t&&x(m,"disabled",e.t=p),e},{e:void 0,t:void 0}),b(()=>x(k,"value",d())),b(()=>x(A,"value",u())),w(),n})()}J(["input","click"]);export{ge as default};
