Wednesday, March 11, 2015

Oracle: Reset SYS Password

Follow this exercise only if you forgot both SYS and SYSTEM password.

This is not the utility to renew the current password

IF you forgot SYS and SYSTEM password in Oracle

If you forget or lost both SYS and SYSTEM password, you can reset them without logging in to the database.

Here is a cool utility to reset SYS and SYSTEM password, if you ever loose or forget the passwords for these account.

This is tested in Windows box only ( orapwd should work in Unix too)
---------------------------------------------------------------------

1) Go to services ( start -> Run->Services.msc)
2) Stop all Oracle services.
3) Find PWDxxxx.ora file. It is usually located in the Oracle\product\11.x\db_x\database.
xxxx stands for your Oracle SID. For example, if you database is called ORCL, then the file will be PWDorcl.ora
4) Back up the existing file (just rename the file).
5) Generate new PWDxxxx.ora file using orapwd utility.
6) Go to command prompt, type
ORAPWD file=path_to_the_PWDxxx.ora_file password=zzzz
zzzz will the new password for both SYS and SYSTEM account



7) Now you will see a new PWDxxx.ora file generated.
8) Restart your Oracle service
9) You should be able to connect to the database with the new password.

Saturday, March 7, 2015

android damaged sd card

My phone crashed while loading a game, and upon reboot it said "Damaged SD card", consider rebooting it.

When I connected my SD card to my laptop (via a cardreader/SD Adapter), It was able to read all files, so the SD card wasn't really damaged.

I ran the following command via command prompt, and it fixed it

chkdsk /x /f <sd card drive>

/x stands for "Forces the volume to dismount first if necessary. All opened handles to the volume would then be invalid"

/f stands for "Fixes errors on the disk."

 

Thursday, December 11, 2014

C# SAML

I recently had to develop SSO Authentication for our hosted application using SAML, and hopefully this will help you.

WHY SAML?
If you have a Web application, and would like to implement SSO (Single Sign On), then you need to ask this key questions.
1) Where is the application hosted ? Is it in house or hosted in cloud ?

In House Hosting: In this case you really don't need SAML, as you can work directly with Active Directory or Windows Authentication etc

Hosted in Cloud: This is where you typically implement SAML. As most clients wont be interested in opening up their AD to internet.

You can check SAML for more info, but here are few key concepts.

Your Web application (Service Provider SP) will contact Client's SSO (Identity Provider IDP) to authenticate an user trying to login to your application. IDP will provide the authentication information in a base 64 encoded XML string called  SAML Assertion. Your application needs to parse the assertion string and figure out the Authentication information ( typically user name and how long a session is valid)

Here is how the information flows

1) User tries to access your application
2) Your code needs to check if an SAMLResponse variable is available in the "Form Parameters"
3) If SAMLResponse is Null, you need to redirect to Clients SSO Page ( could be Ping, F5 etc.,)
4) User will enter his credentials there, and if successful, it will redirect back to your application login page.
5) When the redirect comes back from client SSO, SAML Response vairable will be set and it wont be null
6) SAML Response or SAML Assetion is a Base64 encoded string. You may need a certificate from client to decode the string to a XML Document
7) You parse the XML Document, get the authentication information, and let them in.

There are 3 things you need before you start your coding

1) Clients SSO URL.
2) You need to provide an URL of your application to the client. This is where Client's SSO will redirect upon successful login  (step 1)
3) Certificate information from client ( to read the SAML Assertion string)

Here is my code


       









Thursday, November 20, 2014

Oracle: How to use Constants defined in a package in SQL Statement

I have an Oracle package with 100+ Constants defined.  I wanted to use those constants in a SQL, and couldn't find any easy option.

I Found this solution in StackOverflow from "Björn", which is brilliant. I just changed the return to Varchar2 instead of number, so it will work for all data types

----------------------------------------------------------------------------------------------------------------
Create or Replace Function get_constant (i_constant IN Varchar2)  RETURN Varchar2 deterministic AS
   output Varchar2(4000);
Begin

   execute immediate 'begin :output := '||i_constant||'; end;' using out output;   
   Return output;

End;
/
----------------------------------------------------------------------------------------------------------------

Create or Replace Package My_Constants as

number_constant constant int := 9;
varchar2_constant constant varchar2(200) :='Hello There';
Date_Constant constant date := sysdate;
end;
/
select get_constant('My_Constants.number_constant'),
       get_constant('My_Constants.varchar2_constant'),
       get_constant('My_Constants.Date_Constant')
     from dual;