Skip to content

Commit

Permalink
Fully implemented authentication and cracked, closes #16 and fixed so…
Browse files Browse the repository at this point in the history
…me other bugs
  • Loading branch information
JBou committed Apr 18, 2014
1 parent 548d6b5 commit ab4f030
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 82 deletions.
2 changes: 1 addition & 1 deletion MinecraftLauncher/Windows/Login.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ComboBox x:Name="cb_existing_users" VerticalAlignment="Top" Margin="10,10,168,0" Height="25" DisplayMemberPath="displayName" />
<TextBox x:Name="tb_username" VerticalAlignment="Top" Margin="10,101,10,0" Height="26" />
<Label VerticalAlignment="Top" Margin="10,70,10,0" Height="26" Content="Email Addresse oder Username:" />
<PasswordBox x:Name="pb_password" VerticalAlignment="Top" Margin="10,163,10,0" Height="26" />
<PasswordBox x:Name="pb_password" VerticalAlignment="Top" Margin="10,163,10,0" Height="26" IsEnabled="{Binding ElementName=cb_online_mode,Path=IsChecked}" />
<Label VerticalAlignment="Top" Margin="10,132,10,0" Height="26" Content="Passwort:" />
<TextBlock VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,127,10,0" Height="26" FontSize="9" >
<Hyperlink NavigateUri="https://help.mojang.com/customer/portal/articles/1233873" RequestNavigate="Hyperlink_RequestNavigate">
Expand Down
71 changes: 47 additions & 24 deletions MinecraftLauncher/Windows/Login.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,23 @@ Public Class Login
'Login with access token
Try
Dim Account = DirectCast(cb_existing_users.SelectedItem, authenticationDatabase.Account)
Dim session = New Session() With {.AccessToken = Account.accessToken,
.ClientToken = authenticationDatabase.clientToken,
.SelectedProfile = Nothing}
Await session.Refresh
authenticationDatabase.List.Where(Function(p) p.uuid = Account.uuid).First.accessToken = session.AccessToken
Await authenticationDatabase.Save()
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = session.SelectedProfile.Id
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Main.lbl_Username.Content = "Willkommen, " & session.SelectedProfile.Name
If Guid.TryParse(Account.userid, New Guid) Then
Dim session = New Session() With {.AccessToken = Account.accessToken,
.ClientToken = authenticationDatabase.clientToken,
.SelectedProfile = Nothing}
Await session.Refresh
authenticationDatabase.List.Where(Function(p) p.uuid = Account.uuid).First.accessToken = session.AccessToken
Await authenticationDatabase.Save()
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = session.SelectedProfile.Id
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Await Main.ShowUsername_Avatar(session.SelectedProfile.Name)
Else
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = Account.uuid.Replace("-", "")
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Await Main.ShowUsername_Avatar(Account.displayName)
End If
Main.Show()
Me.Visibility = System.Windows.Visibility.Collapsed
Main.TabControl_main.Visibility = System.Windows.Visibility.Visible
Expand All @@ -74,17 +81,31 @@ Public Class Login
Dim capturedException As MinecraftAuthenticationException = Nothing
'login with username & password
Try
Session = Await JBou.Authentication.Session.DoLogin(tb_username.Text, pb_password.Password)
authenticationDatabase.clientToken = Session.ClientToken
If authenticationDatabase.List.Select(Function(p) p.uuid.Replace("-", "")).Contains(Session.SelectedProfile.Id) Then
authenticationDatabase.List.Remove(authenticationDatabase.List.Where(Function(p) p.uuid.Replace("-", "") = Session.SelectedProfile.Id).First)
If cb_online_mode.IsChecked Then
Session = Await JBou.Authentication.Session.DoLogin(tb_username.Text, pb_password.Password)
authenticationDatabase.clientToken = Session.ClientToken
If authenticationDatabase.List.Select(Function(p) p.uuid.Replace("-", "")).Contains(Session.SelectedProfile.Id) Then
authenticationDatabase.List.Remove(authenticationDatabase.List.Where(Function(p) p.uuid.Replace("-", "") = Session.SelectedProfile.Id).First)
End If
authenticationDatabase.List.Add(Session.ToAccount)
Await authenticationDatabase.Save()
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = Session.SelectedProfile.Id
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Await Main.ShowUsername_Avatar(Session.SelectedProfile.Name)
Else
Dim account As New authenticationDatabase.Account() With {
.displayName = tb_username.Text,
.username = tb_username.Text,
.uuid = Guid.NewGuid.ToString,
.userid = tb_username.Text}
authenticationDatabase.List.Add(account)
Await authenticationDatabase.Save()
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = account.uuid.Replace("-", "")
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Await Main.ShowUsername_Avatar(account.displayName)
End If
authenticationDatabase.List.Add(Session.ToAccount)
Await authenticationDatabase.Save()
Dim profile As Profiles.Profile = Await Profiles.FromName(ViewModel.selectedprofile)
profile.playerUUID = Session.SelectedProfile.Id
Await Profiles.Edit(ViewModel.selectedprofile, profile)
Main.lbl_Username.Content = "Willkommen, " & Session.SelectedProfile.Name
Main.Show()
Me.Visibility = System.Windows.Visibility.Collapsed
Main.TabControl_main.Visibility = System.Windows.Visibility.Visible
Expand All @@ -101,10 +122,12 @@ Public Class Login
Dim capturedException As MinecraftAuthenticationException = Nothing
Try
Dim Account = DirectCast(cb_existing_users.SelectedItem, authenticationDatabase.Account)
Dim session = New Session() With {.AccessToken = Account.accessToken,
.ClientToken = authenticationDatabase.clientToken,
.SelectedProfile = Nothing}
Await session.Invalidate()
If Guid.TryParse(Account.userid, New Guid) Then
Dim session = New Session() With {.AccessToken = Account.accessToken,
.ClientToken = authenticationDatabase.clientToken,
.SelectedProfile = Nothing}
Await session.Invalidate()
End If
authenticationDatabase.List.Remove(authenticationDatabase.List.Where(Function(p) p.uuid = Account.uuid).First)
Await authenticationDatabase.Save()
Load_Accounts()
Expand Down
Loading

0 comments on commit ab4f030

Please sign in to comment.