How to use randomstring - 10 common examples

To help you get started, we’ve selected a few randomstring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpdb / server / src / app / profile / profile.api.spec.js View on Github external
it('should succeed the second time providing the same username', async () => {

			// 1. create github user
			const oauth = await api.createOAuthUser('github');
			const username = api.generateUser().username;
			const pass = randomString.generate(10);

			// 2. add local credentials
			await api.withToken(oauth.token)
				.patch('/v1/profile', { username: username, password: pass })
				.then(res => res.expectStatus(200));

			// 3. add (again) local credentials
			await api.withToken(oauth.token)
				.patch('/v1/profile', { username: username, password: pass })
				.then(res => res.expectStatus(200));
		});
	});
github oauthinaction / oauth-in-action-code / exercises / ch-11-ex-1 / authorizationServer.js View on Github external
if (req.body.approve) {
		if (query.response_type == 'code') {
			// user approved access

			var rscope = getScopesFromForm(req.body);
			var client = getClient(query.client_id);
			var cscope = client.scope ? client.scope.split(' ') : undefined;
			if (__.difference(rscope, cscope).length > 0) {
				var urlParsed = buildUrl(query.redirect_uri, {
					error: 'invalid_scope'
				});
				res.redirect(urlParsed);
				return;
			}

			var code = randomstring.generate(8);
			
			var user = getUser(req.body.user);
			
			// save the code and request for later
			
			codes[code] = { request: query, scope: rscope, user: user };
		
			var urlParsed = buildUrl(query.redirect_uri, {
				code: code,
				state: query.state
			});
			res.redirect(urlParsed);
			return;
		} else {
			// we got a response type we don't understand
			var urlParsed = buildUrl(query.redirect_uri, {
github oauthinaction / oauth-in-action-code / exercises / ch-11-ex-2 / completed / authorizationServer.js View on Github external
if (req.body.approve) {
		if (query.response_type == 'code') {
			// user approved access

			var rscope = getScopesFromForm(req.body);
			var client = getClient(query.client_id);
			var cscope = client.scope ? client.scope.split(' ') : undefined;
			if (__.difference(rscope, cscope).length > 0) {
				var urlParsed = buildUrl(query.redirect_uri, {
					error: 'invalid_scope'
				});
				res.redirect(urlParsed);
				return;
			}

			var code = randomstring.generate(8);
			
			var user = getUser(req.body.user);
			
			// save the code and request for later
			
			codes[code] = { request: query, scope: rscope, user: user };
		
			var urlParsed = buildUrl(query.redirect_uri, {
				code: code,
				state: query.state
			});
			res.redirect(urlParsed);
			return;
		} else {
			// we got a response type we don't understand
			var urlParsed = buildUrl(query.redirect_uri, {
github oauthinaction / oauth-in-action-code / exercises / ch-11-ex-5 / authorizationServer.js View on Github external
if (client.client_secret != clientSecret) {
		console.log('Mismatched client secret, expected %s got %s', client.client_secret, clientSecret);
		res.status(401).json({error: 'invalid_client'});
		return;
	}
	
	if (req.body.grant_type == 'authorization_code') {
		
		var code = codes[req.body.code];
		
		if (code) {
			delete codes[req.body.code]; // burn our code, it's been used
			if (code.request.client_id == clientId) {

				var access_token = randomstring.generate();
				var refresh_token = randomstring.generate();

				nosql.insert({ access_token: access_token, client_id: clientId, scope: code.scope });
				nosql.insert({ refresh_token: refresh_token, client_id: clientId, scope: code.scope });

				console.log('Issuing access token %s', access_token);

				var token_response = { access_token: access_token, token_type: 'Bearer',  refresh_token: refresh_token, scope: code.scope.join(' ') };

				res.status(200).json(token_response);
				console.log('Issued tokens for code %s', req.body.code);
				
				return;
			} else {
				console.log('Client mismatch, expected %s got %s', code.request.client_id, clientId);
				res.status(400).json({error: 'invalid_grant'});
				return;
github testdrivenio / testdriven-app-2.5 / cypress / integration / register.spec.js View on Github external
const randomstring = require('randomstring');

const username = randomstring.generate();
const email = `${username}@test.com`;
const password = 'greaterthanten';


describe('Register', () => {
  it('should display the registration form', () => {
    cy
      .visit('/register')
      .get('h1').contains('Register')
      .get('form')
      .get('input[disabled]')
      .get('.validation-list')
      .get('.validation-list > .error').first().contains(
        'Username must be greater than 5 characters.');
  });
github dashersw / cote / test / request-response.js View on Github external
test.cb('Responder throws unknown error', (t) => {
    t.plan(1);

    const key = r.generate();

    const originalListeners = process.listeners('uncaughtException');

    process.removeAllListeners('uncaughtException');

    process.on('uncaughtException', function(err) {
        if (err.message != 'unknown error') {
            originalListeners.forEach((l) => l(err));

            throw err;
        }

        t.pass();
        t.end();
    });
github peerplays-network / peerplays-core-gui / web / app / components / Register / RegisterForm.jsx View on Github external
handleInitialize() {
    this.props.initialize({
      password: RandomString.generate({
        length: 52,
        charset: 'alphanumeric'
      })
    });
  }
github tomjschuster / sequelize-ui / server / api.js View on Github external
router.post('/create/db', (req, res, next) => {
  let key = randomstring.generate()
  let folderPath = path.join(__dirname, 'temp', `${key}`)
  let filePath = path.join(folderPath, 'db.zip')

  mkdirp(folderPath, err => {
    if (err) next(err)

    let models = req.body.models
    let archive = archiver('zip')
    let output = fs.createWriteStream(filePath)

    archive.pipe(output)

    archive.append(_db, { name: '_db.js' })
    models.forEach(model =>
      archive.append(makeModelFile(model), {
        name: `${camelCase(model.name)}.js`
github TaWeiTu / InforGo / interface / static / js / bingo_server.js View on Github external
function randomString(length){
	return rdmString.generate(length);
}
github vladimiry / ElectronMail / src / electron-main / database / index.spec.ts View on Github external
function buildFolder(): Folder {
    return {
        pk: randomstring.generate(),
        raw: "{}",
        id: randomstring.generate(),
        name: randomstring.generate(),
        folderType: MAIL_FOLDER_TYPE.SENT,
        mailFolderId: "123",
    };
}

randomstring

A module for generating random strings

MIT
Latest version published 1 month ago

Package Health Score

80 / 100
Full package analysis

Popular randomstring functions

Similar packages