You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to make a login page which users will users use username and password to see Mainwindow.xaml that generated by WPF UI Template. Here is my code ;
This is the Login.xaml.cs
` public partial class Login
{
private MainWindowViewModel viewModel;
private PageService pageService;
private NavigationService navigationService;
private readonly AuthenticationService _authService;
public LoginViewModel ViewModel { get; }
public Login()
{
InitializeComponent();
_authService = new AuthenticationService(); // AuthenticationService örneği
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
string username = UsernameText.Text; // Kullanıcı adı TextBox'ı
string password = PasswordText.Password; // Şifre PasswordBox'ı
if (_authService.Authenticate(username, password))
{
System.Windows.MessageBox.Show("Giriş başarılı!", "Bilgi", System.Windows.MessageBoxButton.OK, MessageBoxImage.Information);
DialogResult = true; // Login başarılı -> Giriş ekranını kapat
Close();
}
else
{
System.Windows.MessageBox.Show("Kullanıcı adı veya şifre hatalı.", "Hata", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}`
That's the AuthenticationService.cs
`public class AuthenticationService
{
private readonly Dictionary<string, string> _users;
public AuthenticationService()
{
// Örnek kullanıcılar: Kullanıcı adı ve şifre çiftleri
_users = new Dictionary<string, string>
{
{ "admin", "12345" }, // Kullanıcı adı: admin, Şifre: 12345
{ "user1", "password" }
};
}
/// <summary>
/// Kullanıcı adı ve şifre doğrulaması yapar.
/// </summary>
/// <param name="username">Kullanıcı adı</param>
/// <param name="password">Şifre</param>
/// <returns>Doğrulama sonucu (true/false)</returns>
public bool Authenticate(string username, string password)
{
return _users.TryGetValue(username, out var storedPassword) && storedPassword == password;
}
}`
ApplicationHostService ;
` private async Task HandleActivationAsync()
{
// Login.xaml'i başlangıç ekranı olarak göster
if (!Application.Current.Windows.OfType().Any())
{
var loginWindow = new Login();
bool? loginResult = loginWindow.ShowDialog(); // Giriş ekranını modal olarak göster
if (loginResult != true || !UserIsAuthenticated())
{
// Kullanıcı giriş yapmadıysa uygulamayı kapat
Application.Current.Shutdown();
return;
}
}
// Kullanıcı doğrulandıysa MainWindow'u başlat
if (!Application.Current.Windows.OfType<MainWindow>().Any())
{
_navigationWindow = (
_serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow
)!;
_navigationWindow!.ShowWindow();
_navigationWindow.Navigate(typeof(Premium.Views.Pages.DashboardPage));
}
await Task.CompletedTask;
}`
To Reproduce
...
Expected behavior
If user credentials are true I want to switch to mainwindow
Screenshots
OS version
Windows 10
.NET version
.NET 8.0
WPF-UI NuGet version
3.0.5
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
I try to make a login page which users will users use username and password to see Mainwindow.xaml that generated by WPF UI Template. Here is my code ;
This is the Login.xaml.cs
` public partial class Login
{
private MainWindowViewModel viewModel;
private PageService pageService;
private NavigationService navigationService;
private readonly AuthenticationService _authService;
}`
That's the AuthenticationService.cs
`public class AuthenticationService
{
private readonly Dictionary<string, string> _users;
}`
ApplicationHostService ;
` private async Task HandleActivationAsync()
{
// Login.xaml'i başlangıç ekranı olarak göster
if (!Application.Current.Windows.OfType().Any())
{
var loginWindow = new Login();
bool? loginResult = loginWindow.ShowDialog(); // Giriş ekranını modal olarak göster
}`
To Reproduce
...
Expected behavior
If user credentials are true I want to switch to mainwindow
Screenshots
OS version
Windows 10
.NET version
.NET 8.0
WPF-UI NuGet version
3.0.5
Additional context
No response
The text was updated successfully, but these errors were encountered: