حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

ورود با نام کاربری و رمزعبور

تمرین آسان 9444 visibility link download flag trending_up پربازدید

برنامه ای بنویسید که نام کاربری و رمزعبور کاربر رو دریافت کند و طبق اطلاعات زیر، بررسی کند که نام کاربری و رمز عبور وارد شده صحیح است یا خیر؟


username - password
amirhossein - 12345
hooshang - 009922
manizhe - 00000
mahsa - m11m3


مثال

username: amirhossein
password: 12345
ok


username: amirhossein2
password: 12345
error
👨‍💻 1 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 68

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("username: ");
        String username = scanner.nextLine();

        System.out.print("password: ");
        String password = scanner.nextLine();

        if ((username.equals("amirhossien") && password.equals("12345"))
                || (username.equals("hooshang") && password.equals("009922"))
                || (username.equals("manizhe") && password.equals("00000"))
                || (username.equals("mahsa") && password.equals("m11m3"))) {
            System.out.println("ok");
        } else {
            System.out.println("error...");
        }

        scanner.close();
    }
}
پاسخ هوش مصنوعی Ai Java
N = input("username to register: ")
P = input("password to register: ")
n = input("enter your username: ")
p = input("enter your password: ")

if n == N and p == P:
 print("welcome to the website.")
else:
 print("your password or username is incorrect.")
'''
حل به ۳ روش
|
:حل به روش شرط
'''
user = input('write username: ')
password = input('write password: ')

if user == 'test1' and password == '12345':
print('user is authorized(ok)')
elif user == 'test2' and password == '00000':
print('user is authorized')
elif user == 'test3' and password =='010101':
print('user is authorized')
elif user == 'test4' and password == '10101010':
print('user is authorized')
else:
print("user doesn't exist(error)")

'''حل به روش ارزیابی با دیکشنری'''
usernames = {
'test1': '12345',
'test2': '00000',
'test3': '010101',
'test4': '10101010',
}
user = input('enter username: ')
password = input('enter password: ')
if usernames[user] and usernames[user] == password:
print('ok')
else:
print('error')

''' حل به روش ارزیابی نام کابری و رمز با نشانه گذاری ایندکس نام کاربری و رمز در لیست نام کاربری'''
username = ['test1', 'test2', 'test3', 'test4']
pas = ['12345', '00000', '010101', '10101010']
user = input('username: ')
password = input('password: ')
if user in username and password == pas[username.index(str(user))]:
print('ok')
else:
print('error')
fun main() {
    val map1 = mutableMapOf("amirhossein" to "12345",
        "hooshang" to "009922","manizhe" to "00000" , "mahsa" to "m11m3"  )
    while(true){
        try {
            println("Please Enter  your UserName")
            print("UserName:  ")
            val user = readlnOrNull()!!
            println("Please Enter Your PassWord")
            print("Password:  ")
            val password = readlnOrNull()!!
            val mainUser = user.lowercase()
            if (map1[mainUser] == password) {
                println("You have successfully logged in Site")
                break
            } else {
                println("UserName Or Password Is Incorrect")
                println("please try again !! ")
            }
        }catch(e:Exception){
            println(e.message)
        }
    }
}
a1 = input("username: ")
a2 = input("password: ")
if a1 == "amirhossein" and a2 == "12345":
    print("welcome")
elif a1 == "hooshang" and a2 == "009922":
    print("welcome")
elif a1 == "manizhe" and a2 == "00000":
    print("welcome")
elif a1 == "mahsa" and a2 == "m11m3":
    print("welcome")
else: 
    print("wrong username or password")
users = {
    "amirhossein": "12345",
    "hooshang": "009922",
    "manizhe": "00000",
    "mahsa": "m11m3"
}
max_attempts = 3
attempts = 0

while attempts < max_attempts:
    username = input("Enter your username: ")

    if username in users:  # آیا کاربر وجود دارد؟
        password = input("Enter your password: ")

        if users[username] == password:  # آیا رمز درست است؟
            print(f"Welcome {username}!")
            break
        else:
            print("Incorrect password. Try again.")
            attempts += 1
    else:
        print("Username not found. Try again.")
        attempts += 1

if attempts >= max_attempts:
    print("Too many failed attempts. Try again later.")
user = input('Enter username : ')
password = input('Enter password : ')

def check_user (user,password):
    users = [['amirhossein','12345'],['hooshang','009922'],['manizhe','00000'],['mahsa','m11m3']]
    res = False
    for i in users:
        if i[0] == user and i[1] == password:
            res = True
            break
        else:
            res = False
    if res:
        return 'OK'
    else:
        return 'ERROR'

print(check_user(user,password))

# دریافت نام کاربری و کلمه عبور از ورودی
user_Name = input("Enter your userName :")
user_Pass = input("Enter your password :")

# چک کردن نام کاربری و کلمه عبورها
if (user_Name == "amirhossein" and user_Pass == "12345")\
        or (user_Name == "hooshang" and user_Pass == "009922")\
        or (user_Name == "manizhe" and user_Pass == "00000")\
        or (user_Name == "mahsa" and user_Pass == "m11m3"):
    print("valid username and password")
else:
    print("Not valid username and password")
neme = input('neme: ')
password = input('password: ')

if neme == 'amir' and password == 'abcd':
    print('ok')
elif neme == 'ali' and password == '1234':
    print('ok')
elif neme == 'amir ali' and password == '5678':
    print('ok')
else:
    print('error')

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن