查看单个帖子
旧 2008-11-02, 15:25   #7
dafei0214
初级会员
 
注册日期: 2008-10-18
年龄: 42
帖子: 5
声望力: 0
dafei0214 正向着好的方向发展
默认 回复: 密码登陆窗口代码【原创】

搞这个纯属好玩来着,没想要大家买啊。。。。大家交流下吧。。。虽说很简单,但如果在做保密性较高的项目时还是必要的。
具体思路:输入密码时,在keypress函数里检测输入的按键,如果是图形字符,显示星号,并讲键入的字符存为全局变量,当输入del或backspace时,清除全局变量和星号;当输入为enter或点击确认时,开始比较所键入的全局变量值与密码,当然,用户名要对应密码。

function varargout = a1(varargin)
% A1 M-file for a1.fig
% A1, by itself, creates a new A1 or raises the existing
% singleton*.
%
% H = A1 returns the handle to a new A1 or the handle to
% the existing singleton*.
%
% A1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in A1.M with the given input arguments.
%
% A1('Property','Value',...) creates a new A1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before a1_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to a1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help a1

% Last Modified by GUIDE v2.5 25-Oct-2008 21:22:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @a1_OpeningFcn, ...
'gui_OutputFcn', @a1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before a1 is made visible.
function a1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to a1 (see VARARGIN)

% Choose default command line output for a1
handles.output = hObject;
set(handles.a1_code,'String','');
set(handles.a1_user,'String','');
handles.xinghao = '';
handles.user='dafei0214';
handles.code='87406';
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes a1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = a1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

function a1_user_Callback(hObject, eventdata, handles)
% hObject handle to a1_user (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of a1_user as text
% str2double(get(hObject,'String')) returns contents of a1_user as a double


% --- Executes during object creation, after setting all properties.
function a1_user_CreateFcn(hObject, eventdata, handles)
% hObject handle to a1_user (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function a1_code_Callback(hObject, eventdata, handles)
% hObject handle to a1_code (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)set(hObject,'foregroundcolor',[1 1 1]); 40% Hints: get(hObject,'String') returns contents of a1_code as text
% str2double(get(hObject,'String')) returns contents of a1_code as a double
% set(handles.a1_code,'foregroundcolor',[1 1 1]);

% --- Executes during object creation, after setting all properties.
function a1_code_CreateFcn(hObject, eventdata, handles)
% hObject handle to a1_code (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
set(hObject,'UserData','');
set(hObject,'String','');
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes on button press in a1_cancer.
function a1_cancer_Callback(hObject, eventdata, handles)
% hObject handle to a1_cancer (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% set(handles.a1_user,'UserData','','string','');
set(handles.a1_code,'UserData','','string','');
close(gcf);
clear
clc
% --- Executes on button press in a1_ok.
function a1_ok_Callback(hObject, eventdata, handles)
% hObject handle to a1_ok (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
passChar = get(handles.a1_code,'UserData');
userChar = get(handles.a1_user,'String');
if strcmp(passChar,handles.code)&strcmp(userChar,handles.user)
% msgbox('登陆成功!');
close(gcf);
close(a1);
figure(lianxi02);
set(gcf,'name','系统界面BY罗华飞QQ335340681');
else
set(handles.a1_code,'string','','UserData','');
msgbox('用户名或密码错误!');
handles.xinghao='';
guidata(hObject,handles);
end

% --- Executes when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on key press over a1_code with no controls selected.
function a1_code_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to a1_code (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% set(hObject,'fontSize',10);
currChar = get(gcf,'CurrentCharacter');
oldChar = get(hObject,'UserData');
xinghao=get(hObject,'string');
userChar=get(handles.a1_user,'string');
if isstrprop(currChar,'graphic')
oldChar = [oldChar currChar];
xinghao=[handles.xinghao '*'];
set(hObject,'UserData',oldChar,'string',xinghao);
handles.xinghao=xinghao;
guidata(hObject,handles);
elseif double(currChar)==26|double(currChar)==8
oldChar='';
handles.xinghao='';
set(hObject,'UserData',oldChar,'string',handles.xinghao);
guidata(hObject,handles);
elseif double(currChar)==13
set(hObject,'string',xinghao);
if strcmp(oldChar,handles.code)&strcmp(userChar,handles.user)
% msgbox('登陆成功!');
close(gcf);
close(a1);
figure(lianxi02);
set(gcf,'name','系统界面BY罗华飞QQ335340681');
else
set(hObject,'string','','UserData','');
handles.xinghao='';
guidata(hObject,handles);
msgbox('用户名或密码错误!');
handles.xinghao='';
guidata(hObject,handles);
end
else
set(hObject,'UserData',oldChar);
set(hObject,'string',handles.xinghao);
end
dafei0214 当前离线   回复时引用此帖