Create Login in WPF, MVVM Pattern, C# and SQL Server - Step by Step + Display user data
Vložit
- čas přidán 7. 07. 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
I truly appreciate you ... this is an awesome tutorial. And breaking down the MVVM principles like this is golden. Thank you.
true
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;
Learn from an expert. Wonderful tutorials for professional also
Finally! Thank you for this.
thank you for the great video!
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.
Really well explained
Great video .. Thank you👌
Magic !
I'm a french student in IT and your tuto helped me so much, tank you !!
tank you too for the nice comment
I am student too, in the netherlands. Good luck in your studies, frenchie!
Good luck! :)
Thank You, Adblocker
Please keep going with this series. you videos are some of the best out there. Thank you
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 ?
Thank u
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?
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?
Aw, you jumped on WPF, guess Ill need to catch up on you when I learn more of windows forms. :)
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 :)
@@RJCodeAdvanceEN what about the animation , storyboard
@@RJCodeAdvanceEN You mean to tell me if I follow the backend code it will work as well ? :O
Great videos sir !!!
please can teach us how to deploy a winforms app in local area network(LAN)? thanks...
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?
do u know where u can make an username and password
Does someone know how to create a sql server ? I have an error when I try to connect to my database
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.
"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?"
i cannot connect to my sql, my name sever is SQLEXPRESS so _connectionString = @"Server=SQLEXPRESS; Database=MVVMLoginDb; Integrated Security=True".Is that right?
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?
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
Если ты это смотришь и ты такой же тупой как и я,то в строке подключения к бдэшке нужно два слэша,и посмотри на метанит как выглядит подключение
Спасибо, мой друг!
what If I want to use a command parameter? how can I do that?
System.Data.OleDb.OleDbException: 'Must declare the scalar variable "@username".' how to connect
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.
This code is not fetching and displaying data on the screen. Where can I check this for fix. Any kind of help is appreciated.
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?
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
@@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!
@@miyano2544 do u know where u can make an username and password
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?
have you found a solution to the problem?
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)
@@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.
@@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 :)
can you make more videos with mongodb
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.
its happend to me too you have the solution?
@@nirnafrin4707 It is embarrassing, but I found that I just made a typo in the word Password (three S :)) .
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.
do u know where u can make an username and password
I am having this issue. Did you find the solution? Please help.
@@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"
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
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
@@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
Has anyone had any luck contacting the content creator? I'd really like to get info on why I keep getting a "System.NotImplementedException" at the 30 min. 10 sec. mark.
what about security? like hwid-protect and anti-dump
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.
@@RJCodeAdvanceEN you can make name space: jmp 20491mp
dumpers can think it's jump to a code
How do I make and use the database?
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
This code is not checked in to github.
I get a error with the sql server i cant connect.
I had the same problem. I changed in Repository.cs _connectionString to "Server=(local)\\SQLExpress; Database=MVVMLoginDb; Integrated Security=true";
@@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!
@@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
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
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.
@@exogendesign4582do u know where u can make an username and password
do u know where u can make an username and password
@@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.
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.
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.
before loginView.Close(); add if (mainView.IsLoaded) { loginView.Close(); }