Changeset 2379


Ignore:
Timestamp:
Jan 18, 2011, 10:10:46 PM (11 years ago)
Author:
kopal
Message:
  • changing user name and/or password in settings now changes these also on the connect view
  • removed the lase message boxes and replaced them by label outputs
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/Internal/ConnectionManager.cs

    r2358 r2379  
    146146            if (String.IsNullOrEmpty(P2PSettings.Default.PeerName))
    147147            {
    148                 P2PManager.GuiLogMessage("Peer-to-peer not fully configured: username missing.", NotificationLevel.Error);
     148                P2PManager.GuiLogMessage("Peer-to-peer not fully configured: username missing.", NotificationLevel.Info);
    149149                return false;
    150150            }
     
    153153            {
    154154                P2PManager.GuiLogMessage("Peer-to-peer not fully configured: password missing.",
    155                                          NotificationLevel.Error);
     155                                         NotificationLevel.Info);
    156156                return false;
    157157            }
     
    160160            {
    161161                P2PManager.GuiLogMessage("Peer-to-peer not fully configured: world name missing.",
    162                                          NotificationLevel.Error);
     162                                         NotificationLevel.Info);
    163163                return false;
    164164            }
  • trunk/CrypP2P/Internal/P2PBase.cs

    r2360 r2379  
    3939using PeersAtPlay.P2POverlay.Chord;
    4040using PeersAtPlay.P2PStorage.WebDHT;
     41using System.Security.Cryptography;
    4142
    4243/* TODO:
     
    200201                                        NotificationLevel.Info);
    201202            IsInitialized = true;
    202             Dht.Initialize(P2PSettings.Default.PeerName, P2PSettings.Default.Password, P2PSettings.Default.WorldName, overlay,
     203            Dht.Initialize(P2PSettings.Default.PeerName, DecryptString(P2PSettings.Default.Password), P2PSettings.Default.WorldName, overlay,
    203204                           bootstrapper, linkmanager, null);
    204205        }
     
    537538        }
    538539
     540        /// <summary>
     541        /// Encrypts the given string using the current windows user password and converts
     542        /// this to a base64 string
     543        /// </summary>
     544        /// <param name="s"></param>
     545        /// <returns>encrypted base64 string</returns>
     546        public static string EncryptString(string s)
     547        {
     548            byte[] bytes = Encoding.Unicode.GetBytes(s);
     549            byte[] encBytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
     550            return Convert.ToBase64String(encBytes);
     551        }
     552
     553        /// <summary>
     554        /// Decrypts the given base64 string using the current windows user password
     555        /// </summary>
     556        /// <param name="s"></param>
     557        /// <returns>decrypted string</returns>
     558        public static string DecryptString(string s)
     559        {
     560            if (string.IsNullOrEmpty(s))
     561            {
     562                return "";
     563            }
     564            try
     565            {
     566                byte[] encBytes = Convert.FromBase64String(s);
     567                byte[] bytes = ProtectedData.Unprotect(encBytes, null, DataProtectionScope.CurrentUser);
     568                return Encoding.Unicode.GetString(bytes);
     569            }
     570            catch (Exception)
     571            {
     572                return "";
     573            }
     574        }
     575
     576
    539577        #endregion
    540578    }
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ConnectView.xaml

    r2376 r2379  
    1 <GUI:P2PUserControl x:Class="Cryptool.P2PEditor.GUI.Controls.ConnectTab" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:GUI="clr-namespace:Cryptool.P2PEditor.GUI" xmlns:Converters="clr-namespace:Cryptool.P2PEditor.Converters" mc:Ignorable="d" d:DesignHeight="550" d:DesignWidth="360" IsVisibleChanged="P2PUserControl_IsVisibleChanged">
     1<GUI:P2PUserControl x:Class="Cryptool.P2PEditor.GUI.Controls.ConnectTab" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:GUI="clr-namespace:Cryptool.P2PEditor.GUI" xmlns:Converters="clr-namespace:Cryptool.P2PEditor.Converters" mc:Ignorable="d" d:DesignHeight="550" d:DesignWidth="360" IsVisibleChanged="P2PUserControl_IsVisibleChanged" Loaded="P2PUserControl_Loaded">
    22        <GUI:P2PUserControl.Resources>
    33                <Converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
     
    1010        <ScrollViewer VerticalScrollBarVisibility="Auto">
    1111                    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="15,15,15,15">
    12                 <Label FontSize="20" HorizontalContentAlignment="Center">CrypTool 2.0</Label>
    13                 <Label FontSize="13" HorizontalContentAlignment="Center">Distributed Computing Platform</Label>               
     12                <Label FontSize="20" HorizontalContentAlignment="Center" Width="200">CrypTool 2.0</Label>
     13                <Label FontSize="13" HorizontalContentAlignment="Center" Width="200">Distributed Computing Platform</Label>
    1414                <Image Width="200" Name="WorldIcon" Source="..\..\images\connected.png" RenderTransformOrigin="0.5,0.5">
    1515                    <Image.RenderTransform>
     
    1717                    </Image.RenderTransform>
    1818                </Image>
    19                 <Label>Username:</Label>
    20                 <TextBox Name="Username" TextChanged="Username_TextChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    21                 <TextBlock FontSize="12" MouseDown="GetACertificateLabel_Click" Cursor="Hand" HorizontalAlignment="Right" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" Foreground="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ForegroundColorConverter}}">
     19                <Label Name="MessageLabel" Foreground="Red" Content="" Grid.Row="1" Grid.ColumnSpan="2" />
     20                <Label Width="200">Username:</Label>
     21                <TextBox Width="200" Name="Username" TextChanged="Username_TextChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
     22                <TextBlock Width="200" FontSize="12" MouseDown="GetACertificateLabel_Click" Cursor="Hand" HorizontalAlignment="Center" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" Foreground="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ForegroundColorConverter}}">
    2223                    <Underline>Create a new account</Underline>
    2324                </TextBlock>
    24                 <Label>Password:</Label>
    25                 <PasswordBox Name="Password" PasswordChanged="Password_PasswordChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
    26                 <TextBlock FontSize="12" MouseDown="ForgotPasswordLabel_Click" Cursor="Hand" HorizontalAlignment="Right" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" Foreground="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ForegroundColorConverter}}">
     25                <Label Width="200">Password:</Label>
     26                <PasswordBox Width="200" Name="Password" PasswordChanged="Password_PasswordChanged" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
     27                <TextBlock Width="200" FontSize="12" MouseDown="ForgotPasswordLabel_Click" Cursor="Hand" HorizontalAlignment="Center" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" Foreground="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource ForegroundColorConverter}}">
    2728                    <Underline>Forgot password</Underline>
    2829                </TextBlock>
    2930                <Label/>
    30                 <Button Name="ConnectButton" IsDefault="True" Content="Connect" Height="38" FontFamily="Consolas" FontSize="20" Click="ConnectButtonClick" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />               
     31                <Button Width="200" Name="ConnectButton" IsDefault="True" Content="Connect" Height="38" FontFamily="Consolas" FontSize="20" Click="ConnectButtonClick" IsEnabled="{Binding IsP2PConnecting, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />               
    3132            </StackPanel>
    3233        </ScrollViewer>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/ConnectView.xaml.cs

    r2376 r2379  
    99using Cryptool.PluginBase;
    1010using System.IO;
     11using System.ComponentModel;
    1112
    1213namespace Cryptool.P2PEditor.GUI.Controls
     
    5556                    , null);         
    5657                }
    57             });
    58 
     58            });           
    5959        }
    6060
    6161        private void ConnectButtonClick(object sender, RoutedEventArgs e)
    6262        {
     63            this.MessageLabel.Visibility = Visibility.Hidden;
    6364            try
    6465            {
    6566                if (CertificateServices.GetPeerCertificateByAvatar(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PeersAtPlay" + Path.DirectorySeparatorChar + "Certificates" + Path.DirectorySeparatorChar),
    66                     P2PSettings.Default.PeerName, P2PSettings.Default.Password) == null)
     67                    P2PSettings.Default.PeerName, P2PBase.DecryptString(P2PSettings.Default.Password)) == null)
    6768                {
    68                     System.Windows.MessageBox.Show("Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!", "Can not connect.");
     69                    this.MessageLabel.Content = "Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!";
     70                    this.MessageLabel.Visibility = Visibility.Visible;
    6971                    return;
    7072                }
     
    7274            catch (NoCertificateFoundException)
    7375            {
    74                 System.Windows.MessageBox.Show("Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!", "Can not connect.");
     76                this.MessageLabel.Content = "Cannot connect, account \"" + P2PSettings.Default.PeerName + "\" not found!";
     77                this.MessageLabel.Visibility = Visibility.Visible;
    7578                return;
    7679            }           
    7780            catch (Exception ex)
    7881            {
    79                 System.Windows.MessageBox.Show("Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message), "Can not connect.");
     82                this.MessageLabel.Content = "Cannot connect using account \"" + P2PSettings.Default.PeerName + "\": " + (ex.InnerException != null ? ex.InnerException.Message : ex.Message);
     83                this.MessageLabel.Visibility = Visibility.Visible;
    8084                return;
    8185            }
     
    125129            }
    126130        }
     131
     132        private void OnPropertyChanged_Settings(object sender, PropertyChangedEventArgs args)
     133        {           
     134            if(args.PropertyName.Equals("PeerName")){
     135                //this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     136                //{
     137                    if (this.Username.Text != ((P2PEditorSettings)sender).PeerName)
     138                    {
     139
     140                        this.Username.Text = ((P2PEditorSettings)sender).PeerName;
     141                    }
     142                //},null);
     143            }
     144            if(args.PropertyName.Equals("Password")){
     145                //this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     146                //{
     147                    if (this.Password.Password != ((P2PEditorSettings)sender).Password)
     148                    {
     149                        this.Password.Password = ((P2PEditorSettings)sender).Password;
     150                    }
     151                //},null);
     152            }           
     153        }
     154
     155        private void P2PUserControl_Loaded(object sender, RoutedEventArgs e)
     156        {
     157            ((P2PEditorSettings)((P2PEditor)GetValue(P2PEditorProperty)).Settings).PropertyChanged += OnPropertyChanged_Settings;
     158        }
    127159    }
    128160}
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/GetNewCertificateView.xaml.cs

    r2378 r2379  
    179179                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    180180                        {
    181                             this.MessageLabel.Content = "The username already exists. Please chose another one.";
     181                            this.MessageLabel.Content = "The username already exists. Please choose another one.";
    182182                            this.MessageLabel.Visibility = Visibility.Visible;
    183183                        }, null);
     
    186186                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    187187                        {
    188                             this.MessageLabel.Content = "The email already exists. Please chose another ones.";
     188                            this.MessageLabel.Content = "The email already exists. Please choose another one.";
    189189                            this.MessageLabel.Visibility = Visibility.Visible;
    190190                        }, null);
  • trunk/CrypPlugins/P2PEditor/P2PEditorSettings.cs

    r2378 r2379  
    2424using System.Security.Cryptography;
    2525using System;
     26using Cryptool.P2P.Internal;
    2627
    2728namespace Cryptool.P2PEditor
     
    112113        public string Password
    113114        {
    114             get { return settings.Password; }
    115             set
    116             {
    117                 if (value != settings.Password)
    118                 {
    119                     settings.Password = value;
     115            get { return P2PBase.DecryptString(settings.Password); }
     116            set
     117            {
     118                if (P2PBase.EncryptString(value) != settings.Password)
     119                {
     120                    settings.Password = P2PBase.EncryptString(value);
    120121                    OnPropertyChanged("Password");
    121122                    HasChanges = true;
     
    356357            P2PSettings.Default.Save();
    357358        }
     359
    358360    }
    359361}
Note: See TracChangeset for help on using the changeset viewer.