express 4.x login dialog box when you open the page

// open the pop-up page log dialog
 App . Use ( function (REQ, RES, Next) {
     var the auth = REQ. Headers [ 'Authorization' ];
     IF ( the auth ) {
         var tmp = the auth . Split ( '' );
         var buf = new new Buffer ( tmp [ . 1 ], 'Base64' );
         var plain_auth = buf . toString ();
         varcreds = plain_auth . Split ( ':' );
         var username = creds [ 0 ];
         var password = creds [ . 1 ];
         IF (( username == 'ADMIN' ) && ( password == 'ADMIN' )) {
             // authentication is successful, allows access to
 return the Next (); 
        } 
    } // let the browser login dialog box, the status must be set to 401, Header set-authenticate the WWW
 RES. the sET ( 'the WWW-authenticate' ,            

        'Basic realm=""');
    res.status(401).end();
});
 

Guess you like

Origin blog.csdn.net/F2004/article/details/51918396