How to create API Key Generator


We often need the API key Generator for some Softwares, Web Application to make a licensing system. In this tutorial I will show you how to create an API key generator in jQuery.

This script will randomly generate API Keys. You can implement this code in your system.



  1. Bootstrap 4
  2. jQuery


<!doctype html>
<html lang="en">
		<!-- Required meta tags -->
		<title>Generate API Key Demo - CodeHasBug</title>
		<meta name="description" content="This is a demo of API key generator" />
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- Bootstrap CSS -->
		<link rel="stylesheet" href="" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
		<link rel="icon" href="" sizes="32x32" />
		<link rel="icon" href="" sizes="192x192" />
		<link rel="apple-touch-icon" href="" />
		<meta name="msapplication-TileImage" content="" />
				position: relative;
				height: 80px;
		<div class="container">
			<div class="row">
				<div class="col-12 mt-5 text-center">
					<h1>Api Key Generator</h1>
			<div class="row justify-content-center mt-3">
				<div class="col-8">
					<input type="text" id="api" class="form-control text-center read-only" placeholder="Generate New API key">
			<div class="row justify-content-center mt-3">
				<div class="col-6">
					<button id="genApi" class="btn btn-danger btn-block">Generate API Key</button>
				<div class="col-6">
					<a href="" class="btn btn-info btn-block">Back To tutorial</a>
			<div class="spacer"></div>
		<script src=""></script>
		<script src=""></script>
				$("#genApi").click( function(){
					var d = new Date().getTime();
					if( window.performance && typeof === "function" ){
						d +=;
					var api= 'xxxxxxxx-xxxx-6xxx-yxxx-xxxxxx5xxxxx'.replace(/[xy]/g, function(c){
						var r = (d + Math.random()*16)%16 | 0;
						d = Math.floor(d/16);
						return (c=='x' ? r : (r&0x3|0x8)).toString(16);

About Ashis Biswas

A web developer who has a love for creativity and enjoys experimenting with the various techniques in both web designing and web development. If you would like to be kept up to date with his post, you can follow him.

Leave a Comment