dafei0214
2008-10-26, 06:07
今天本来想下载一个密码登陆窗口的程序,无奈没有金币,只好自己花了几个小时,编了这个简单的小程序,和大家互相交流下。。。小弟学这个才两周不到。。。
:)
使用方法:
将附件解压至英文目录下,打开matlab 7.0,输入命令GUIDE,选择a1.fig。
用户名:dafei0214
密码:87406
登陆成功后会启动系统界面。
欢迎大家多提意见。。。
QQ:335340681
我发一个免费的,我可不是跟楼主对着干,互相交流而已。
function mima
OldHandle = findobj( 'Type', 'figure', 'Tag', 'mimadenglu' ) ;
if ishandle( OldHandle )
close( OldHandle ) ;
end
fig = figure ;
set(fig,'units','normalized','position',[0.3 0.2 0.4 0.6],...
'menubar','none','name','密码登陆窗口',...
'numbertitle','off','color',[0.925 0.914 0.847],'tag','mimadenglu');
scnsize=get(0,'screensize');
font_size1=round(20*sqrt(scnsize(3)*scnsize(4)/(1024*768)));
font_size2=round(14*sqrt(scnsize(3)*scnsize(4)/(1024*768)));
uicontrol(fig,'style','text','units','normalized','pos',[0.1 0.63 0.8 0.15],'string','欢迎使用本系统',...
'fontsize',font_size1,'fontweight','bold','fontunits','normalized','bac',[0.925 0.914 0.847])
panel1=uipanel(fig,'units','normalized','pos',[0.15 0.3 0.7 0.15],'bac',[0.925 0.914 0.847]);
uicontrol(panel1,'style','edit','units','normalized','pos',[0.2 0.2 0.6 0.6],...
'string','','tag','edit1','backgroundcolor',[1 1 1],'string','请输入密码',...
'fontsize',font_size2,'fontunits','normalized','KeyPressFcn',...
['currKey = get(gcf,''Currentkey'');',...
'currChar = get(gcf,''Currentcharacter'');',...
'switch currKey;',...
'case {''backspace'',''delete''};',...
'Char = [];',...
'set(gcbo,''String'','''');',...
'drawnow;',...
'case ''return'';',...
'passChar = get(gcbo,''UserData'');',...
'if strcmp(passChar,''654321'');',...
'msgbox(''恭喜你记住了密码!!!'');',...
'else;',...
'msgbox(''密码输入错误!!!'');',...
'end;',...
'return;',...
'otherwise;',...
'oldChar = get(gcbo,''UserData'');',...
'Char = [oldChar,currChar];',...
'set(gcbo,''string'',char(''*''*ones(1,length(Char))));',...
'end;',...
'set(gcbo,''UserData'',Char);'])
dafei0214
2008-11-02, 15:25
搞这个纯属好玩来着,没想要大家买啊。。。。大家交流下吧。。。虽说很简单,但如果在做保密性较高的项目时还是必要的。
具体思路:输入密码时,在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
nothingwmm
2008-12-24, 13:39
我发一个免费的,我可不是跟楼主对着干,互相交流而已。
function mima
OldHandle = findobj( 'Type', 'figure', 'Tag', 'mimadenglu' ) ;
if ishandle( OldHandle )
close( Ol...
免费才是硬道理呀!!!!!!!!
谢老师真好
以上两位高手的源代码在我这运行的时候都显示的是Error: Missing variable or function.请告诉原因吧:cool:
vBulletin® v3.8.3,版权所有 ©2000-2025,Jelsoft Enterprises Ltd.