Validate Login Details

Soma Sekhar M
Tera Contributor

I have a one custom application that will contain a user registration form , login form , varieties of books with their description and price.

When I submit details from login page i need to validate user name and password of the registered users how can i write a code to validate? if its valid i will display the list of books otherwise give an alert like enter a valid username and password.

13 REPLIES 13

jaheerhattiwale
Mega Sage
Mega Sage

@Soma Sekhar M After submitting the login page use the user name and password to query registered users table. If you find the record present in Registered users table then show the books else not

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi jaheer As per ur guidelines I tried with Below Script Include and business rule I applied business rule on Login after insert Business rule

(function executeRule(current, previous /*null when async*/) {
//var a=current.user_name;
//var b=current.password;
var ga = new HelloWorld;
ga.helloWorld();


// Add your code here

})(current, previous);

with the below Script Include

var HelloWorld = Class.create();
HelloWorld.prototype ={
initialize:function(){

},

helloWorld: function() {
var answer = 'false';
var usrEmail =current.user_name;
var usrpsw=current.password;
var gr = new GlideRecord('x_881103_book_cart_user_details');
gr.addQuery('email_id',usrEmail);
gr.addQuery('password',usrpsw);
gr.query();
while(gr.next())
{
answer = 'true';
}
if(answer == 'true')
{
gs.setRedirect("https://dev51184.service-now.com/now/nav/ui/classic/params/target/x_881103_book_cart_books_list.do%3...");
// top.window.location="https://dev51184.service-now.com/now/nav/ui/classic/params/target/x_881103_book_cart_books_list.do%3...";
// return false;
}
},

type: 'HelloWorld'
};

Let me know if is there Any mistake in my code and correct me accordingly 

@Soma Sekhar M We can do much with Password 1 way encrypted field. Is it possible for you to change the field type of password field to password 2 way?

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale I didn't able to change the type but i can delete the existing password field and i will create a new password field with password 2 way encrypted .

@Soma Sekhar M After changing the field type to password 2 way, please write the following script in business rule. Dont need script include.

 

(function executeRule(current, previous /*null when async*/ ) {

var gr = new GlideRecord('x_881103_book_cart_user_details');
gr.addQuery('email_id', current.user_name.toString());
gr.query();
while (gr.next()) {
if (gr.password.getDecryptedValue() == current.password.toString()) {
gs.setRedirect("https://dev51184.service-now.com/now/nav/ui/classic/params/target/x_881103_book_cart_books_list.do%3...");
}
}


})(current, previous);

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023