From f0e32abc4fdd5dc1ff9779c18b2c217764575981 Mon Sep 17 00:00:00 2001 From: Michael Albert Date: Mon, 10 Feb 2020 18:07:10 +0100 Subject: [PATCH] Fix QR code creation Change-Id: If05856a6fdafa43a93c6b57963820710db188d42 --- src/components/ShowUserPdf.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/ShowUserPdf.js b/src/components/ShowUserPdf.js index 321bedf..124d749 100644 --- a/src/components/ShowUserPdf.js +++ b/src/components/ShowUserPdf.js @@ -5,23 +5,17 @@ import { PDFExport } from "@progress/kendo-react-pdf"; import QRCode from "qrcode.react"; function xor(a, b) { - var res = "", - i = a.length, - j = b.length; - while (i-- > 0 && j-- > 0) - res = (parseInt(a.charAt(i)) ^ parseInt(b.charAt(j))).toString() + res; + var res = ""; + for (var i = 0; i < a.length; i++) { + res += String.fromCharCode(a.charCodeAt(i) ^ b.charCodeAt(i % b.length)); + } return res; } function calculateQrString(serverUrl, username, password) { - var magicString = "wo9k5tep252qxsa5yde7366kugy6c01w7oeeya9hrmpf0t7ii7"; - + const magicString = "wo9k5tep252qxsa5yde7366kugy6c01w7oeeya9hrmpf0t7ii7"; var urlString = "user=" + username + "&password=" + password; - while (urlString.length > magicString.length) { - magicString += magicString; - } - urlString = xor(urlString, magicString); // xor with magic string urlString = btoa(urlString); // to base64 @@ -86,7 +80,11 @@ const ShowUserPdf = props => { var qrCode = ""; var displayname = ""; - if (props.location.state) { + if ( + props.location.state && + props.location.state.id && + props.location.state.password + ) { const { id, password } = props.location.state; const username = id.substring(1, id.indexOf(":"));