11import { BADGES } from "./helpers/badge.js" ;
2+ import { md5 } from "./libs/crypto/md5.js" ;
23
34const managerBtn = '<i class="fa-solid fa-unlock-keyhole"></i>' ;
45
@@ -33,11 +34,11 @@ export default {
3334 en : "Open manager" ,
3435 } ,
3536 onClick : async function openManager ( ) {
36- let curPass = await locker . password . get ( ) ;
37- if ( curPass == null ) {
38- curPass = await initPassword ( ) ;
37+ let hasPass = await locker . password . has ( ) ;
38+ if ( ! hasPass ) {
39+ hasPass = await initPassword ( ) ;
3940 }
40- if ( curPass ) {
41+ if ( hasPass ) {
4142 window . open ( "/scripts/auto_lockWebsite.html" , "_self" ) ;
4243 }
4344 } ,
@@ -61,8 +62,8 @@ export default {
6162 } ,
6263 onClick : async ( ) => {
6364 const { t } = await import ( "../popup/helpers/lang.js" ) ;
64- let password = await locker . password . get ( ) ;
65- if ( password == null ) {
65+ let hasPass = await locker . password . has ( ) ;
66+ if ( ! hasPass ) {
6667 Swal . fire ( {
6768 icon : "warning" ,
6869 title : t ( {
@@ -92,11 +93,10 @@ export default {
9293 } ,
9394 onClick : async ( ) => {
9495 try {
95- let password = await locker . password . get ( ) ;
96- if ( password == null ) {
97- return ;
98- }
99- lockCurrentWebsite ( password ) ;
96+ const pass = await locker . password . get ( ) ;
97+ if ( pass == null ) return ;
98+
99+ lockCurrentWebsite ( pass ) ;
100100 locker . sites . add ( location . hostname ) ;
101101 } catch ( e ) {
102102 console . error ( e ) ;
@@ -124,11 +124,17 @@ export const _storage = {
124124export const locker = {
125125 password : {
126126 storageKey : "auto_lock_website_manager_password" ,
127+ async compare ( pass ) {
128+ return md5 ( pass ) === ( await _storage . get ( this . storageKey ) ) ;
129+ } ,
130+ async has ( ) {
131+ return ( await _storage . get ( this . storageKey ) ) != null ;
132+ } ,
127133 get ( ) {
128134 return _storage . get ( this . storageKey ) ;
129135 } ,
130136 set ( pass ) {
131- return _storage . set ( this . storageKey , pass ) ;
137+ return _storage . set ( this . storageKey , md5 ( pass ) ) ;
132138 } ,
133139 remove ( ) {
134140 return _storage . remove ( this . storageKey ) ;
@@ -192,8 +198,8 @@ export async function initPassword(createNew = false) {
192198export async function checkPass ( reason ) {
193199 const { t } = await import ( "../popup/helpers/lang.js" ) ;
194200
195- let curPass = await locker . password . get ( ) ;
196- if ( curPass == null ) return "not init" ;
201+ let hasPass = await locker . password . has ( ) ;
202+ if ( ! hasPass ) return "not init" ;
197203
198204 const { value : pass } = await Swal . fire ( {
199205 icon : "info" ,
@@ -221,7 +227,7 @@ export async function checkPass(reason) {
221227 } ,
222228 } ) ;
223229
224- if ( pass === curPass ) return true ;
230+ if ( await locker . password . compare ( pass ) ) return true ;
225231 if ( pass != null ) {
226232 await Swal . fire (
227233 t ( { vi : "Sai mật khẩu" , en : "Wrong password!" } ) ,
@@ -359,7 +365,7 @@ function lockCurrentWebsite(pass, matchedPattern) {
359365 const unlockTemporarly = overlay . querySelector ( "input#unlock-temporarly" ) ;
360366 const inputPass = overlay . querySelector ( "input#password" ) ;
361367 inputPass . addEventListener ( "input" , ( e ) => {
362- if ( e . target . value == pass ) {
368+ if ( md5 ( e . target . value ) == pass ) {
363369 overlay . style . top = "-100vh" ;
364370 style . disabled = true ;
365371 inputPass . value = "" ;
0 commit comments