Create Login in WPF, MVVM Pattern, C# and SQL Server - Step by Step + Display user data

Поделиться
HTML-код
  • Опубликовано: 7 июн 2024
  • ⏮️ Previous Video: WPF UI/ Design a Modern Login Form/ Introducing to WPF
    • WPF UI/ Design a Moder...
    ⏭️ Next Video: WPF & MVVM/ Modern Main UI Design
    • WPF & MVVM/ Modern Mai...
    🎞️ Hi, in this tutorial we will learn how to Create Login Form in WPF, MVVM Pattern, C# and SQL Server, additionally we will display the data of the current user in the main window.
    Content:
    00:00 Introduction to MVVM
    02:18 Database
    02:53 Implement View Models
    03:25 ViewModel Base Class (INotifyPropertyChanged)
    04:20 ViewModel Command Class (ICommand)
    06:33 Login ViewModel Class
    11:44 Set Binding between the View & ViewModel
    13:49 Create a Bindable PasswordBox (Dependency Property)
    19:50 Implement Models
    20:33 Implement Data Access Objects
    26:28 Register the user in the Thread
    27:33 Configure Application Startup
    30:19 Retrieve and Display user data (Again using MVVM)
    ⬇️ DOWNLOAD PROJECT
    rjcodeadvance.com/inicio-de-s...
    📲 Social Media:
    Facebook: / rjcodeadvanceen
    Instagram: / rjcodeadvanceen
    Website: rjcodeadvance.com
    #WPF #MVVM #LoginForm #SQL #ModernForm #modernui #design #CSharp #VisualBasic #VB.NET #VisualStudio #Custom #Chart #FlatUI #Desktop

Комментарии • 79

  • @kunleth
    @kunleth Год назад +6

    I truly appreciate you ... this is an awesome tutorial. And breaking down the MVVM principles like this is golden. Thank you.

  • @jeffersonjrsinoy4905
    @jeffersonjrsinoy4905 Год назад +7

    Just started developing using WPF, your tutorials really helped me a lot 👍👍👍
    Just wanted to share @ 25:22
    Instead of writing : validUser = command.ExecuteScalar() == null ? false : true;
    I used : validUser = command.ExecuteScalaer() != null;

  • @entemolu1
    @entemolu1 Год назад +4

    Learn from an expert. Wonderful tutorials for professional also

  • @ghelonicomaligaya3232
    @ghelonicomaligaya3232 Год назад +1

    Finally! Thank you for this.

  • @hasanmougharbel8030
    @hasanmougharbel8030 Год назад +2

    I feel blessed learning from this channel. I have simply a general enquiry as a newbie sql learner.
    I realized recently that i may need to write in languages other than sql on the database engine, like, python, C#
    What is the best practice to integrate several languages inside the same database management software.
    Should i look forward to a particular text editor or is there other features that may facilitate multi-language integrations inside database system.

  • @user-zp1po5us1e
    @user-zp1po5us1e Год назад

    thank you for the great video!

  • @minoubrc4773
    @minoubrc4773 8 месяцев назад

    Really well explained

  • @ilianabenchikh9330
    @ilianabenchikh9330 Год назад +1

    I'm a french student in IT and your tuto helped me so much, tank you !!

    • @FrenzyNull
      @FrenzyNull Год назад

      tank you too for the nice comment

    • @StrawHatGyro
      @StrawHatGyro 8 месяцев назад +1

      I am student too, in the netherlands. Good luck in your studies, frenchie!

    • @DirePantsDim
      @DirePantsDim 8 месяцев назад

      Good luck! :)

  • @sirinebibicha2024
    @sirinebibicha2024 Год назад

    Great video .. Thank you👌

  • @MrJuche23
    @MrJuche23 Год назад +1

    Please keep going with this series. you videos are some of the best out there. Thank you

  • @inhnguyen-zq6tq
    @inhnguyen-zq6tq Год назад +1

    Magic !

  • @bennzzen86
    @bennzzen86 Год назад

    Thank You, Adblocker

  • @son1powa
    @son1powa 9 месяцев назад +1

    First of all thanks for your given time for this tutorial.
    I'm developper since 8 years now and MVVM seems so much complicated and so many things to add and re add etc i'm a little lost with so many classes.
    Juste for asking, why don't you use Datasets to interact with the SQL ?
    you create the same object to be as the database is but you only have 4 fileds is it worth it with a complete database in real life ?

  • @user-ry8we7iy5r
    @user-ry8we7iy5r Год назад

    Hi. Your video is just amazing. But if I did everything in one window? That is, from the authorization UserControl I can open the UserControl
    registration or UserControl navigation menu depending on what the user will do in UserControl authorization. How to implement it?

  • @robertorinaldi977
    @robertorinaldi977 10 месяцев назад +2

    Great video, I learned a lot from it!
    However, I noticed that there is a problem on the login View.
    If you run the app and click close without logging in, an exception will be thrown. How to solve it?

  • @janslanina2209
    @janslanina2209 Год назад

    Aw, you jumped on WPF, guess Ill need to catch up on you when I learn more of windows forms. :)

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Год назад +1

      Thanks for watching my videos, well the only difference between WPF and WinForms is the way you design the UI (C# Only - XAML & C#), however everything else is the same :)

    • @entemolu1
      @entemolu1 Год назад

      @@RJCodeAdvanceEN what about the animation , storyboard

    • @janslanina2209
      @janslanina2209 Год назад

      @@RJCodeAdvanceEN You mean to tell me if I follow the backend code it will work as well ? :O

  • @huihui7477
    @huihui7477 5 месяцев назад

    "Hello, I recently came across your videos on C-Sharp WPF tutorials. I'd like to ask, should I start watching from the MVVM playlist, or from the WPF playlist?"

  • @josaphatkayombo9057
    @josaphatkayombo9057 Год назад

    Great videos sir !!!
    please can teach us how to deploy a winforms app in local area network(LAN)? thanks...

  • @easylearning-8153
    @easylearning-8153 8 месяцев назад

    Thank u

  • @ZacharyRodney
    @ZacharyRodney Год назад

    excellent video. the best I've found so far for practical project walkthroughs that include best practices. I followed along without issue and at the end I'm finding an issue that is hard to debug. the login command is not triggering the "username or password is incorrect" or the view change event. hard to debug. I understand what is happening in the code, but not sure how to correct it. any suggestions?

    • @Aiden-lu3vj
      @Aiden-lu3vj Год назад

      do u know where u can make an username and password

  • @tuannguyenvanquoc2670
    @tuannguyenvanquoc2670 Год назад

    i cannot connect to my sql, my name sever is SQLEXPRESS so _connectionString = @"Server=SQLEXPRESS; Database=MVVMLoginDb; Integrated Security=True".Is that right?

  • @wsilvawgt
    @wsilvawgt Месяц назад

    Could you help me to synchronize with SQL Server Management Studio in WPF, MVVM Pattern, C#
    I can't, I created the same form as you, I modified it my way but I can't connect to SQL Server Management

  • @wsilvawgt
    @wsilvawgt Месяц назад

    Could you help how to create user roles and privileges?
    as an administrator, access to everything
    managing member with access to everything but the administrator can modify something
    and Ordinance with access to everything else the administrator will modify manually.

  • @Elta305
    @Elta305 Год назад

    Does someone know how to create a sql server ? I have an error when I try to connect to my database

  • @miyano2544
    @miyano2544 Год назад

    It's what I'm looking. Thank you! Also I'm wondering; It's possible OAuth2 login system using Google/Discord API? I Searched too long but i didn't find anything... Can you give me a referance or advice?

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Год назад +1

      Hi thanks.
      Well, honestly, I haven't, but it's possible. uses Google APIs.
      "The library supports OAuth2.0 authentication. Strongly-typed per-API libraries are generated using Google's Discovery API."
      www.nuget.org/profiles/google-apis-packages

    • @miyano2544
      @miyano2544 Год назад

      @@RJCodeAdvanceEN Thank you for answer! I'll look that library. I hope I can also find a way for Discord OAuth2. Love you and your content!

    • @Aiden-lu3vj
      @Aiden-lu3vj Год назад

      @@miyano2544 do u know where u can make an username and password

  • @deakattila
    @deakattila 9 месяцев назад

    what If I want to use a command parameter? how can I do that?

  • @jatinkamble7720
    @jatinkamble7720 Год назад

    System.Data.OleDb.OleDbException: 'Must declare the scalar variable "@username".' how to connect

  • @kumarabhishekranjan4694
    @kumarabhishekranjan4694 8 месяцев назад

    This code is not fetching and displaying data on the screen. Where can I check this for fix. Any kind of help is appreciated.

  • @doannam5900
    @doannam5900 Год назад

    At 30:10 when I tried to Execute, after I clicked Login, it throw an exception that 'Cannot open database "MVVMLoginDb" requested by the login. The login failed.'. How can I fix that? I hope to recive your help! Thanks for tutorial

    • @Elta305
      @Elta305 Год назад

      Did you find an answer ? I have the same issue, I think it's because we need to create a sql server but idk how to do

    • @rasmuse2713
      @rasmuse2713 11 месяцев назад

      @@Elta305 Of course you need to set up a database on either MS Sql Server or MySql and create a database called "MVVMLoginDb". His database is not public. MySQL is free. And in his video he shows an SQL script that will create the database and table for you: 2:20

  • @SirLuke33
    @SirLuke33 5 месяцев назад

    I've done several tests and I'm not sure if it's the right method. If anyone wants, they can correct me. I use wpf core 8
    from: _connectionString = "Server=(local); Database=MVVMLoginDb; Integrated Security=true";
    to: _connectionString = "Server=(local); Data Source=(localdb)\\MSSQLLocalDB; Database=MVVMLoginDb; Integrated Security=true";
    On a remote server I have no idea how to do it. I'm just starting out.
    Then I made this change.
    Id = reader[0].ToString();
    From an error. I noticed that integers are not generated in the db. The error is that it cannot be converted from int to string. I put a cast (int) and it throws an error. Removing id, it works. I don't know how to change this.

  • @tesladude2822
    @tesladude2822 Год назад +1

    After creating BindablePasswordBox I start having error on InitializeComponent: 'A 'Binding' cannot be set on the 'Password' property of type 'BindablePasswordBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject'. Compared the code and cannot find the error. Please help.

    • @nirnafrin4707
      @nirnafrin4707 Год назад

      its happend to me too you have the solution?

    • @tesladude2822
      @tesladude2822 Год назад

      @@nirnafrin4707 It is embarrassing, but I found that I just made a typo in the word Password (three S :)) .

  • @t3hPoundcake
    @t3hPoundcake Год назад +1

    31:55
    Isn't the System Threading Principal class for the user who is logged into a local machine (or I guess a remote machine possibly)? I'm confused as to why we are using that to pass the username parameter to GetByUsername() instead of what the user types into the Username field and then displaying another error if there is not a username in the table with that string, because on another video I posted about how closing the window from the login form displays a break in the code and it is with this Generic Principal implementation that is causing the null reference exception.
    Have you encountered this error? Do you have any idea how I can fix or would it be better to try and pass the username that is typed into the field as the parameter?

  • @edence6001
    @edence6001 Год назад +4

    Если ты это смотришь и ты такой же тупой как и я,то в строке подключения к бдэшке нужно два слэша,и посмотри на метанит как выглядит подключение

    • @StrawHatGyro
      @StrawHatGyro 8 месяцев назад

      Спасибо, мой друг!

  • @xibble4320
    @xibble4320 Год назад +1

    How do I make and use the database?

    • @carapysca1238
      @carapysca1238 Год назад

      Open server exlorer in VS. Then connect to your database. If you dont see your server name insert any of this: . , local, (local)/SQLEXPRESS. Then cooy connection string from properties

  • @thaithanhloc6791
    @thaithanhloc6791 Год назад

    can you make more videos with mongodb

  • @mplaimer
    @mplaimer Год назад

    Great video series but I had one problem in my project.
    14:45 your path for the image doesn´t worked for me. I found 2 other workarounds. pack:\\application:,,,/Images\key-icon.png or ..\Images\key_icon.png.
    This worked for me at Designtime and Runtime! Before, I had an error in the XAML Designer, but the icon was displayed correctly at runtime.
    Maybe someone else has this problem.

    • @Aiden-lu3vj
      @Aiden-lu3vj Год назад

      do u know where u can make an username and password

    • @wamique
      @wamique Год назад

      I am having this issue. Did you find the solution? Please help.

    • @mplaimer
      @mplaimer Год назад

      @@wamique Hello, yes I found a workaround for the problem. I have already written it above, but here again.
      pack:\\application:.../Images\key-icon.png or ..\Images\key_icon.png.
      In my Xaml-Code I use
      ImageSource="..\..\Views\Images\key_icon.png"
      and also
      ImageSource="../Images/user_icon.png"

  • @daliangilbert
    @daliangilbert Год назад +1

    I really wondering what is wrong with the code:
    if (loginView.IsVisible == false && loginView.IsLoaded)
    {
    var mainView = new MainView();
    mainView.Show();
    loginView.Close();
    }
    because when I tried to use it exactly the same as in this tutorial and try to close login window - loginView.IsLoaded becomes true and loginView.IsVisible becomes false what raises an error "Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing". Does somebody know why?

    • @thanderstaff9593
      @thanderstaff9593 Год назад

      have you found a solution to the problem?

    • @Den-Irenicus
      @Den-Irenicus Год назад

      The author forgot to show how renamed MainWindow.xaml to MainView.xaml. Just rename it and dont forget to fix MainView.xaml.cs. And this problem could be fixed by changing Target Framework to .NET Framework 4.8 (from .NET Core)

    • @BreezElly
      @BreezElly Год назад

      @@thanderstaff9593 Not sure if it's correct solution but instead of line "loginView.Close();" i used "loginView.Visibility = Visibility.Hidden;" and it worked just fine.

    • @Xodocl
      @Xodocl 9 месяцев назад

      @@thanderstaff9593 You can add this condition:
      if (Current.ShutdownMode == ShutdownMode.OnExplicitShutdown)
      return;
      before the first. You also need to add this line in the LoginView codebehind in the "btnClose_Click" event handler:
      "Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;" before calling the Shutdown() method.
      This is the first thing that came to mind :)

  • @kopch1k82
    @kopch1k82 Год назад

    what about security? like hwid-protect and anti-dump

    • @RJCodeAdvanceEN
      @RJCodeAdvanceEN  Год назад

      there is no complete way to avoid memory dumps. Obfuscators are also easy to obfuscate.
      What I do is obfuscate the code manually and make life difficult for those who try to decompile my project, when I finish a project I rename everything, such as: namespaces, classes, properties, fields, methods, etc.
      I put any long name, example: fagerge78er78ge4gea9g4aeg
      Although that takes me a long time.

    • @kopch1k82
      @kopch1k82 Год назад

      @@RJCodeAdvanceEN you can make name space: jmp 20491mp
      dumpers can think it's jump to a code

  • @GalaxyTJ
    @GalaxyTJ Год назад

    I get a error with the sql server i cant connect.

    • @Den-Irenicus
      @Den-Irenicus Год назад +2

      I had the same problem. I changed in Repository.cs _connectionString to "Server=(local)\\SQLExpress; Database=MVVMLoginDb; Integrated Security=true";

    • @jedit2586
      @jedit2586 9 месяцев назад +1

      @@Den-Irenicus Hey there, just wanted to say THANKYOU SO MUCH 🙏. I was stuck on this problem for a whole day and couldn't work out what went wrong 😭. Good thing Ifound your comment!

    • @SirLuke33
      @SirLuke33 5 месяцев назад +1

      @@Den-Irenicus HI. I use core 8 and I also get the connection error. I'm just starting out and I still can't fix it. I searched the web for a solution, nothing.
      thank you so much for your help

  • @Fayritail1337
    @Fayritail1337 Год назад +1

    the previous video was way better this one is more confusing than helpful you start just by assuming people know hot to do the database instead of showing them and hot to implement it is confusing if you gonna start SQL video show how to do the database and next hot to build the code

    • @exogendesign4582
      @exogendesign4582 Год назад

      Actually I can create app in c# but watching his style really confuse me, I can follow along and make it work but the problem is I don't understand a damn thing on what I was doing specially Interface, it hurts my brain so I am relearning everything. You should start small too since SQL the easiest thing to do. His Tutorial aren't for begineers but advance C# user.
      Learn about design pattern, Dependency Injection Principle, Interface Segregation Principle, MASTER OOP too then you can get the gist of what his talking.

    • @Aiden-lu3vj
      @Aiden-lu3vj Год назад

      @@exogendesign4582do u know where u can make an username and password

    • @Aiden-lu3vj
      @Aiden-lu3vj Год назад

      do u know where u can make an username and password

    • @exogendesign4582
      @exogendesign4582 Год назад

      @@Aiden-lu3vj what do you mean? you want to create a log in window? you can start small by usung string and saving it to database once you can read it out through your head, add soms flavor to improve security such as hashing and salt, also using encryption such as eramake which is popular with the c# ecosystem. For start search "login form with sql using c#, there's a ton.

  • @adamantiz-
    @adamantiz- 7 месяцев назад

    I don't like that you are doing everything in the code view. I hate XAML.
    Can you please remake the tutorials and show how to do this with the Visual design tools?

  • @t3hPoundcake
    @t3hPoundcake Год назад

    In the App.xaml startup method I'm getting an unhandled exception with the loginView.Close(); call. I cannot figure out what is going on with it, if you click the custom close button while you're on the login screen the application closes and breaks at that line, saying you cannot change the state of a window while it is closing. I've tried a bunch of different ideas and cannot figure out why it's throwing this error. If I try to simply HIDE the loginView, pressing the close button hides the login view and shows the MainView window regardless of if you are logged in or not.

    • @t3hPoundcake
      @t3hPoundcake Год назад

      If anyone is having this issue, simply changing loginView.Close() to loginView.Hide() solves the issue - not sure if that is the best way to handle this but it works and the application can still be closed via the custom close button click event anyway, so it seems to work fine.

    • @TheMBasith
      @TheMBasith 4 месяца назад

      before loginView.Close(); add if (mainView.IsLoaded) { loginView.Close(); }