1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 16:45:16 +00:00

Sign in user

This commit is contained in:
2019-11-23 13:16:28 +01:00
parent 89e612900c
commit 293752b0f4
7 changed files with 234 additions and 8 deletions

View File

@ -27,4 +27,29 @@ export function sha1(str : string) : string {
*/
export function crypt(str : string, salt: string) : string {
return execSync("/usr/bin/php -r \"echo crypt(\'"+str+"\', \'"+salt+"\');\"").toString();
}
/**
* Generate a random integer
*
* @param max Maximum value to except
*/
export function randInt(max: number) : number {
return Math.floor(Math.random() * Math.floor(max));
}
/**
* Generate a random string
*
* @param length The length of the string to generate
* @param keyspace Keyspace to use
*/
export function randomStr(length: number, keyspace : string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") : string {
let str = "";
for (let i = 0; i < length; i++) {
str += keyspace[randInt(keyspace.length)];
}
return str;
}

15
src/utils/StringUtils.ts Normal file
View File

@ -0,0 +1,15 @@
/**
* String utilities
*
* @author Pierre HUBERT
*/
/**
* Check a given email address
*
* @param {String} emailAddress The email address to check
* @return {Boolean} True for a valid email address / false else
*/
export function checkMail(emailAddress: string): boolean {
return (emailAddress.match(/^[a-zA-Z0-9_.]+@[a-zA-Z0-9-.]{1,}[.][a-zA-Z]{2,8}$/) === null ? false : true);
}