Home > Blockchain >  Login Page with ASP.NET Core (MVC)
Login Page with ASP.NET Core (MVC)

Time:07-05

I am trying to learn asp.net core (MVC) , and I am posting this question after trying to implement everything that I could understand from Google.

I want to create a simple login Page. I have earlier worked on asp.net framework with ado.net and webforms using edmx, but I learned that edmx and webforms are now outdated. So, I wanted to learn the new method.

These are the tables and stored procedure I created

create table users(userId int identity(1,1) primary key, username varchar(20), password varchar(20))

create proc login(
@username varchar(20),
@password varchar(20)
)
as
begin
if exists(select * from users where username = @username and password=@password)
select 'Success' as UserExists
else
select 'Failed' as UserExists
end

Then I created the Model Class -

 public class Login
    {   
        [Key]
        public int userId { get; set; }

        [Required(ErrorMessage = "Username is requried!")]
        public string username { get; set; }

        [Required(ErrorMessage = "Password is requried!")]
        public string password { get; set; }
    }

Then I added model in my project. I referred this link

enter image description here

Success:

enter image description here enter image description here enter image description here

Fail:

enter image description here enter image description here

If you have a business need for this, I recommend using Identity. You can refer to this link and this one.

  • Related