2020-04-01 21:47:33 +02:00
|
|
|
import * as sha1 from "../crypto/sha";
|
2021-01-10 17:36:57 +01:00
|
|
|
import {LogCategory, logDebug} from "tc-shared/log";
|
|
|
|
import {tr} from "tc-shared/i18n/localize";
|
2020-04-01 21:47:33 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
export function hashPassword(password: string) : Promise<string> {
|
|
|
|
return new Promise<string>((resolve, reject) => {
|
2020-04-01 21:47:33 +02:00
|
|
|
sha1.sha1(password).then(result => {
|
2020-03-30 13:44:18 +02:00
|
|
|
resolve(btoa(String.fromCharCode.apply(null, new Uint8Array(result))));
|
2018-04-16 20:38:35 +02:00
|
|
|
});
|
2020-03-30 13:44:18 +02:00
|
|
|
});
|
2018-09-30 21:50:59 +02:00
|
|
|
}
|
|
|
|
|
2021-01-10 16:13:15 +01:00
|
|
|
export const copyToClipboard = str => {
|
2021-01-10 17:36:57 +01:00
|
|
|
logDebug(LogCategory.GENERAL, tr("Copy text to clipboard: %s"), str);
|
2021-01-10 16:13:15 +01:00
|
|
|
|
|
|
|
const element = document.createElement('textarea');
|
|
|
|
element.value = str;
|
|
|
|
element.setAttribute('readonly', '');
|
|
|
|
element.style.position = 'absolute';
|
|
|
|
element.style.left = '-9999px';
|
|
|
|
document.body.appendChild(element);
|
|
|
|
|
|
|
|
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
|
|
|
|
|
|
|
element.select();
|
2018-09-30 21:50:59 +02:00
|
|
|
document.execCommand('copy');
|
2021-01-10 16:13:15 +01:00
|
|
|
|
|
|
|
document.body.removeChild(element);
|
2018-09-30 21:50:59 +02:00
|
|
|
if (selected) {
|
|
|
|
document.getSelection().removeAllRanges();
|
|
|
|
document.getSelection().addRange(selected);
|
|
|
|
}
|
|
|
|
};
|