mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Sign in user
This commit is contained in:
@ -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
15
src/utils/StringUtils.ts
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user