4 examples of 'how to check if user already exists in database in jsp' in JavaScript

Every line of 'how to check if user already exists in database in jsp' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
115function checkUserNotExists() {
116 // Send request only if 'Input' is not empty.
117 if ($("#username-input").val()) {
118 $.ajax({
119 url: "is-user-exists",
120 type: "GET",
121 data: {username: $("#username-input").val()},
122
123 success: function result(json) {
124 if (json) {
125 document.getElementById("user-exists").style.display = "block";
126 }
127 else {
128 document.getElementById("user-exists").style.display = "none";
129 }
130 }
131 });
132 }
133}
Important

Use secure code every time

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

6function userExists(email) {
7 var results = api.db.query('users', {
8 email: email
9 });
10
11 if (results.length === 1) {
12 return true;
13 }
14
15 return false;
16}
14export function checkUsernameAlreadyExists(data) {
15 let errors = {};
16
17 return User.query({
18 where: { username: data.username }
19 })
20 .fetch()
21
22 .then((user) => {
23 // User found in database
24 if(user) {
25 if (user.get('username') === data.username) {
26 errors.username = 'This username already exists, please choose different one.';
27 }
28 }
29
30 return {
31 errors,
32 isValid: isEmpty(errors)
33 }
34 });
35}
139export async function checkUsernameExists(username) {
140 const conn = await pgClient.connect();
141 try {
142 const result = await conn.query(
143 `SELECT username FROM ${PG_TN_USERS} WHERE username = $1`,
144 [username.toLowerCase()],
145 );
146 if (result.rows.length > 0) {
147 return true;
148 } else {
149 return false;
150 }
151 } catch (ex) {
152 throw ex;
153 } finally {
154 conn.release();
155 }
156}

Related snippets