From f33c672d41d2c8145449b802486c34d1dcce73bb Mon Sep 17 00:00:00 2001 From: LSvekis Date: Fri, 1 Oct 2021 12:41:35 -0400 Subject: [PATCH] Create password checker --- Chapter 12/password checker | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Chapter 12/password checker diff --git a/Chapter 12/password checker b/Chapter 12/password checker new file mode 100644 index 0000000..0d0fa3d --- /dev/null +++ b/Chapter 12/password checker @@ -0,0 +1,33 @@ +const allowed = ["1234", "pass", "apple"]; + +function passwordChecker(pass) { + return allowed.includes(pass); +} + +function login(password) { + return new Promise((resolve, reject) => { + if (passwordChecker(password)) { + resolve({ + status: true + }) + } else { + reject({ + status: false + }) + } + }) +} + +function checker(pass) { + login(pass) + .then(token => { + console.log('Approve:'); + console.log(token) + }) + .catch(value => { + console.log('Reject:'); + console.log(value) + }) +} +checker('1234'); +checker('wrong');