From 91fb2972b426f5d048d621ba473e30a82b2a8507 Mon Sep 17 00:00:00 2001 From: Alex Booker Date: Fri, 14 Aug 2015 18:12:27 +0100 Subject: [PATCH] added guard clause --- js/passwordGenerator.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/passwordGenerator.js b/js/passwordGenerator.js index 6615d06f..13e7d41b 100644 --- a/js/passwordGenerator.js +++ b/js/passwordGenerator.js @@ -1,5 +1,8 @@ var passwordGenerator = (function() { var generateRandomNum = function (max) { + if (!window.crypto || !window.crypto.getRandomValues) { + throw new Error('Unsupported browser.'); + } var array = new Uint8Array(1); window.crypto.getRandomValues(array); var range = max + 1;