0

I am trying to make password check machine , but it isn't working

import java.util.*; public class password{ public static void main (String args []){ Scanner sc = new Scanner(System.in); System.out.println(" SET YOUR NEW PASSWORD "); System.out.println(); String password=sc.nextLine(); System.out.println(); System.out.println(); System.out.println(" NEW PASSWORD HAS BEEN SET SUCCESSFULLY"); for(int i =3 ; i>0;--i){ System.out.println("ENTER THE PASSWORD TO OPEN YOUR BLOG "); String pass = sc.nextLine(); if(pass.equals("password")) { System.out.println(); System.out.println(); System.out.println(" Hello Welcome to blog , you have successfully entred your password an this project demostrate how security works at backend door"); break; }else { System.out.println("INVALID PASSWORD ,TRY AGAIN "); System.out.println(); System.out.println(i+"attempts left"); System.out.println(); System.out.println();} } } }

28th Feb 2023, 10:23 AM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar
2 Answers
+ 3
if (pass.equals(password)) password is variable name, not a string in your code
28th Feb 2023, 10:39 AM
buster23
buster23 - avatar
+ 1
buster23 thanks bro!! Worked
28th Feb 2023, 12:01 PM
Shubham Swaraj 161
Shubham Swaraj 161 - avatar