Authenticate a user using native authentication request boxes
npm i os-auth
or
npm install os-auth@latest --save
git clone https://github.com/ssight/os-auth.git
osAuth( TITLE, MESSAGE )
Title - The title of the window
Message - The text that is displayed. Note that this has no effect on Linux.
This will return a promise with the value of true
, authenticated, or false
, not authenticated
const osAuth = require('os-auth');
osAuth().then(console.log)
This will ask the user for authentication, printing out true
or false
, depending on weather they inputted their credentials correctly or not.
Since osAuth
returns a promise, the following will also work:
const osAuth = require('os-auth');
(async () => {
var authenticated = await osAuth("Test", "Please enter your username and password");
if (authenticated) {
// The user is authenticated! Do whatever now.
} else {
// The user's entered their username or password wrong.
}
})();
You could also do this:
const osAuth = require('os-auth');
osAuth("Test", "Please enter your username and password").then(authenticated => {
if (authenticated) {
// The user is authenticated! Do whatever now.
} else {
// The user's entered their username or password wrong.
}
}).catch(error => {
// There was an error.
})
-
The
message
property currently has not effect on the prompt in Linux. -
The username is always assumed correct on MacOS, with no box for it.