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

8 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2012 年 4 月 9 日
編集済み: MathWorks Support Team 2022 年 12 月 26 日
データベースとのやり取りを行う MATLAB プログラムを作成し、実行しています。いくつかのデータベースにアクセスする際、パスワードを入力する必要があるのですが、入力中のパスワードを "*" などの文字で隠す方法を教えてください。

採用された回答

MathWorks Support Team
MathWorks Support Team 2022 年 12 月 26 日
編集済み: MathWorks Support Team 2022 年 12 月 26 日
現時点では、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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangeプログラミング についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!