Login with GUI Matlab

Hi, i alrdy success connecting my matlab with ms Access.. The problem is i doesnt know how to query. I have 2 edit text which to ask user to input username n password, after click login the system will refer to my databse. If wrong username n password the messagebox will popout and say fail.. any1 good at query the database can share

1 Commento

Muhamad Ikhwan
Muhamad Ikhwan il 28 Feb 2017
Modificato: Geoff Hayes il 1 Mar 2017
conn = database('cube','','');
sqlquery = 'select Username,Password from Login';
curs = exec(conn,sqlquery);
setdbprefs('DataReturnFormat','structure');
curs = fetch(curs);
curs.Data
a = get(handles.edit1,'String');
b = get(handles.edit2,'String');
l=strcmp(a,b);
if l==1
AdminManagement()
UserManagement()
else
msgbox('wrong pwd');
end

Accedi per commentare.

Risposte (1)

Geoff Hayes
Geoff Hayes il 1 Mar 2017
Muhammad - why are you comparing a with b
l=strcmp(a,b);
if l==1
% etc.
end
Aren't these the username and password and so should be different?
If curs.Data is a cell array (?) of usernames and passwords from the database, then I suspect that you would need to do something like
usernamePwdData = curs.Data;
guiUsername = get(handles.edit1,'String'); % I'm guessing edit1 is for username
guiPassword = get(handles.edit2,'String'); % I'm guessing edit2 is for password
validUser = false;
for k=1:length(usernamePwdData)
username = usernamePwdData{k,1};
password = usernamePwdData{k,2};
if strcmp(username,guiUsername) && strcmp(password,guiPassword)
validUser = true;
break;
end
end
if validUser
AdminManagement()
UserManagement()
else
msgbox('wrong pwd');
end
I'm also assuming that curs.Data is a cell array of N rows and 2 columns. If different, you would need to adjust the above code.

Richiesto:

il 28 Feb 2017

Risposto:

il 1 Mar 2017

Community Treasure Hunt

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

Start Hunting!

Translated by