入力中のパスワードを隠すことはできますか?

7 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 9 Avr 2012
データベースとのやり取りを行う MATLAB プログラムを作成し、実行しています。いくつかのデータベースにアクセスする際、パスワードを入力する必要があるのですが、入力中のパスワードを "*" などの文字で隠す方法を教えてください。

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 26 Déc 2022
Modifié(e) : MathWorks Support Team le 26 Déc 2022
現時点では、MATLABではこのような機能は提供されていません。代替案として以下のような方法があります。
1. ActiveX を使用する方法があります。
2. フォアグラウンドの色とバックグラウンドの色を同じにすることによりタイプされた文字が見えなくなります。
h = uicontrol('Style','Edit','ForeGroundColor',[.75 .75 .75]);
3. 対応されていないフォントを使用することにより、"□"等として表示させることができます。
h = uicontrol('Style','Edit','Fontname','symbol');
4. ユーザコミュニティである MATLAB / File Exchange に関連するコードが公開されています。
・File Exchange: passwordUI
・File Exchange: login
ただし、上記サイトで公開されているプログラムに関するご質問は、プログラム作成者の方に直接お問合せください。
なお、キーボード入力した文字列と、同じ数の * (アスタリスク)を同時に表示するだけの処理であれば、以下のような記述にて行うことが可能です。
function passwd_test
u = uicontrol('style','edit','enable','inactive','backgroundcolor','w',...
'units','norm',...
'position',[.1 .1 .5 .1],...
'tag','edit')
u = uicontrol('style','text','enable','inactive','backgroundcolor','w',...
'units','norm',...
'position',[.1 .25 .5 .1],...
'tag','text')
set(gcf,'keypressfcn', {@handle_passwd})
function handle_passwd(h,eventData)
CK = get(gcf,'currentkey');
h_disp = findobj(gcbf,'tag','text');
h_asterix = findobj(gcbf,'tag','edit');
if gco == h_asterix,
str = get(h_disp,'string');
if strcmp(CK,'backspace'),
% Do something here if the backspace key was pressed
if length(str) > 1,
str = str(1:end-1);
end
elseif strcmp(CK,'space')
str = [str,' '];
else
str = [str,CK];
end
set(h_disp,'string',str);
set(h_asterix,'string',char(ones(1,length(str))*double('*')));
end

Plus de réponses (0)

Catégories

En savoir plus sur プログラミング dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!